Why bot suddenly crashed?
See original GitHub issueThis code was working properly one month ago but since last night it was crashing.
(node:3848) UnhandledPromiseRejectionWarning: Error: 400: Bad Request: message is not modified at buildConfig.then.then.then.then (D:\apps\bot\node_modules\telegraf\core\network\client.js:235:17) at at process._tickCallback (internal/process/next_tick.js:118:7) (node:3848) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:3848) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
code :
app.action('start', (ctx) => {
http.get('http://localhost:3000/api/questions', (res) => {
//res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => {
rawData += chunk;
});
res.on('end', () => {
try {
data = JSON.parse(rawData);
i = Object.keys(data).length;
ctx.editMessageText('Choose one of the options:',
Extra.HTML().markup(m => m.inlineKeyboard([
m.callbackButton(data[x].Q1, 'plus1'),
m.callbackButton(data[x].Q2, 'plus2')
], {
columns: 1
})));
} catch (e) {
console.error(e.message);
}
});
}).on('error', (e) => {
console.error(`Got error: ${e.message}`);
});
});
app.action('plus1', (ctx) => {
if (x < i) {
answer[x] = 1;
ctx.editMessageText('Choose one of the options:', Extra.HTML().markup(m => m.inlineKeyboard([
m.callbackButton(data[x].Q1, 'plus1'),
m.callbackButton(data[x].Q2, 'plus2')
], {
columns: 1
})));
x++;
} else {
ctx.editMessageText('Finished :', Extra.HTML().markup(m => m.inlineKeyboard([
m.callbackButton('Result', 'result')
])));
}
});
app.action('plus2', (ctx) => {
if (x < i) {
answer[x] = 2;
ctx.editMessageText('Choose one of the options', Extra.HTML().markup(m => m.inlineKeyboard([
m.callbackButton(data[x].Q1, 'plus1'),
m.callbackButton(data[x].Q2, 'plus2')
], {
columns: 1
})));
x++;
} else {
ctx.editMessageText('Finished :', Extra.HTML().markup(m => m.inlineKeyboard([
m.callbackButton('Result', 'result')
])));
}});
app.action('result', (ctx) => {
ctx.reply(answer);
});
app.startPolling();
Issue Analytics
- State:
- Created 5 years ago
- Comments:13
Hello @parsarian Then you use
editMessageText
and send to user same content which is not diffs to previous edition of that message - Telegram Bot Api returns this error -Error: 400: Bad Request: message is not modified
So and in your app you don’t handle any error
In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code
You can try to handle this erroror any other errors in your bot
@parsarian , Nope, sendNextQuestion, receive context as param.
data
object with questions will be stored as global variableand line sendNextQuestion(ctx); seems incorrect because of ctx is not defined message, and I changed to sendNextQuestion(data); but steel Cannot read property 'x' of undefined message appear.
ctx is not defined message appears because forgot to rename
ctx
tocontext
atreturn ctx.editMessageText('Choose one of the options:',...
andreturn ctx.editMessageText('Finished :',
lines