You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I adapted the code from the README slightly to get a working example but I get errors...
The first message being sent/received works. But for the second message, I get an error. The server also gets killed after like two seconds. Could you help me with this?
I get this output
error: [polling_error] {}
1) should greet Masha and Sasha
0 passing (845ms)
1 failing
1) Telegram bot test
should greet Masha and Sasha:
Error: Timeout of 800ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/matthias/Code/subroulette_bot/test5.js)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: connect ECONNREFUSED ::1:9001"}
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: connect ECONNREFUSED ::1:9001"}
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: connect ECONNREFUSED ::1:9001"}
error: [polling_error] {"code":"EFATAL","message":"EFATAL: Error: connect ECONNREFUSED ::1:9001"}
…
for mocha test.js where test.js is:
constTelegramServer=require('telegram-test-api');constTelegramBot=require('node-telegram-bot-api');classTestBot{constructor(bot){bot.onText(/\/start/,(msg,match)=>{letchatId=msg.from.id;letopts={reply_to_message_id: msg.message_id,reply_markup: JSON.stringify({keyboard: [[{text: 'ok 1'}]],}),};bot.sendMessage(chatId,'pong',opts);});bot.onText(/ok1/,(msg,match)=>{letchatId=msg.from.id;bot.sendMessage(chatId,'Hello, Masha!',opts);});}}describe('Telegram bot test',()=>{letserverConfig={port: 9001};consttoken='sampleToken';letserver;letclient;beforeEach(()=>{server=newTelegramServer(serverConfig);returnserver.start().then(()=>{client=server.getClient(token);});});afterEach(function(){this.slow(2000);this.timeout(10000);returnserver.stop();});it('should greet Masha and Sasha',asyncfunctiontestFull(){this.slow(400);this.timeout(800);constmessage=client.makeMessage('/start');awaitclient.sendMessage(message);constbotOptions={polling: true,baseApiUrl: server.config.apiURL};consttelegramBot=newTelegramBot(token,botOptions);consttestBot=newTestBot(telegramBot);constupdates=awaitclient.getUpdates();console.log(`Client received messages: ${JSON.stringify(updates.result)}`);if(updates.result.length!==1){thrownewError('updates queue should contain one message!');}letkeyboard=updates.result[0].message.reply_markup.keyboard;console.log("keyboard",keyboard)constmessage2=client.makeMessage(keyboard[0][0].text);awaitclient.sendMessage(message2);console.log("sent message2",message2)// Here, the error occurs:constupdates2=awaitclient.getUpdates();console.log(`Client received messages: ${JSON.stringify(updates2.result)}`);if(updates2.result.length!==1){thrownewError('updates queue should contain one message!');}if(updates2.result[0].message.text!=='Hello, Masha!'){thrownewError('Wrong greeting message!');}returntrue;});});
The text was updated successfully, but these errors were encountered:
Hi, I adapted the code from the README slightly to get a working example but I get errors...
The first message being sent/received works. But for the second message, I get an error. The server also gets killed after like two seconds. Could you help me with this?
I get this output
for
mocha test.js
wheretest.js
is:The text was updated successfully, but these errors were encountered: