question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reply with promises

See original GitHub issue

Hi everyone, within 2 months I used all replies and other interactivity commands with promises and everything was fine. But today I created new project with the last update and encountered with a problem:

bot.start((ctx) => {
  authReq(ctx)
    .then(response => {
      mockup.reply(ctx, 'Success!');
      mockup.reply(ctx, 'Success!');
      console.log(response)
    })
    .catch(err => {
      mockup.reply(ctx, answers.error);
      mockup.toAllAdmins(ctx, 'Start', err);
      console.log(err)
    })
});

where authReq returns Promise, and mockup.reply does a bit the sam as ctx.reply and what is a problem… If I delete one of mockup.reply(ctx, ‘Success!’); user recieve nothing and when I double reply function user recieve Success one time (console.log(response) works). In addition, if there will be an err mockup.reply works with and without toAllAdmins function o_O Is there anything changed in the new update or my code is wrong, pls help…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
dotcypresscommented, Feb 3, 2018

@tva10 @JRakhimov Guys, in provided example I found that you break the promise chain. To fix that, just add return keywords:

/// works fine when webhookReply true
app.command('return', function(context){
	return new Promise(function(res){
		setTimeout(res, 1000);
	}).then(function(){
		console.log('wanna reply');
		RETURN context.reply('you write smth');	
	}).catch(console.log);
});

///	did not work when webhookReply true
app.on('text', function(context){
	RETURN new Promise(function(res){
		setTimeout(res, 1000);
	}).then(function(){
		console.log('wanna reply');
		RETURN context.reply('you write smth');	
	}).catch(console.log);
});

Related issue

2reactions
tva10commented, Feb 3, 2018
const Telegraf = require('telegraf');

const token = ' some bot token';
const lturl = 'local tunnel path';
const path = '/somepath';
const ltport = 8082;


const config = {
	telegram: { webhookReply: true }
};
const app = new Telegraf( token || process.env.BOT_TOKEN, config);

app.use(Telegraf.log());

/// works fine when webhookReply true
app.command('return', function(context){
	return new Promise(function(res){
		setTimeout(res, 1000);
	}).then(function(){
		console.log('wanna reply');
		context.reply('you write smth');	
	}).catch(console.log);
});

///	did not work when webhookReply true
app.on('text', function(context){
	new Promise(function(res){
		setTimeout(res, 1000);
	}).then(function(){
		console.log('wanna reply');
		context.reply('you write smth');	
		//context.reply('success!2');	
	}).catch(console.log);
});

/// works fine too
/// maybe because response not finished yet
app.on('sticker', function(context){
	context.reply('HI!');
});


//app.telegram.setWebhook().then(()=>{ app.startPolling() });

app.telegram.setWebhook(lturl + path).then(()=>{app.startWebhook(path, null, ltport)});
Read more comments on GitHub >

github_iconTop Results From Across the Web

reply to new on promises - by pall s. ardal - JSTOR
REPLY TO NEW ON PROMISES. BY PALL S. ARDAL. Mr. C. G. New argues (this journal, April 1969) that I maintain that. (A)...
Read more >
What is to say, when you ask your friend to promise ... - Quora
With respect, this is the wrong question. The correct questions are: "Am I worthy of trust? And, “Is he/she? Furthermore, the 2 answers...
Read more >
Error handling with promises
Asynchronous actions may sometimes fail: in case of an error the corresponding promise becomes rejected. For instance, fetch fails if the remote server...
Read more >
Replies as Promises · Issue #1557 · nock/nock - GitHub
Context Writing jest mocks for a got client (eg. got.extend()), was looking into dynamically loaded fixtures as replies.
Read more >
Creflo Dollar — How to Respond to the Promise?
We've talked about that, you know, we apprehend and appropriate these things by faith, and thank God for all that. I wanna give...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found