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.

Please support ContextFunc<string> in type of questionText

See original GitHub issue

Now questionText just support string.

Please support ContextFunc<string> in type of questionText too.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Ramin-Batenicommented, Oct 11, 2019

@EdJoPaTo I understand what you say and I have faced with this situation in developing my bots in the past years.

So I have a solution for you! I use my Technic to have stateless ability in reply-to-question situation while the question can have dynamic data.😎


My Technic: I generate a unique sign (a random string) and inject it to the End or Beginning of the question.

For example:

Step 1

Text of question »» What is your name? Generated Sign »» #sE1R2w Step 1 result »» #sE1R2w What is your name?

Now we go ahead and hide the sign by this way:

Step 2

function signQuestion(sign,text){
    signUrl = 'http://wwww.wwwwwwwwwwww.www/';
    signTextLink = `[\u200c](${signUrl}${signTextLink})`
    return signTextLink + text;
}
let finalQuestion = signQuestion('#sE1R2w','What is your name?');

Step 2 result »» [\u200c](http://wwww.wwwwwwwwwwww.www/#sE1R2w)What is your name? What the user see finally if we send the message with markup support »» What is your name?

Step 3

OK! That’s it…👌 Now we can easily check the sign of question instead of text of question when we have reply_to_message:

if( ctx.message.reply_to_message)
{
   const sign = getSignOfMessage(ctx.message.reply_to_message)

    // Now here we check the sign of reply_to_message NOT the text of reply_to_message ;)
   if(sign == ........){
   }
}

function getSignOfMessage(msg){
    const signUrl="http://wwww.wwwwwwwwwwww.www/#";
    let sign;
    f(msg.entities)
    {
        const e = msg.entities.find(i=>i.type=="text_link" && i.url && i.url.indexOf(fakeUrl)>0)
        if(e){
            sign=e.url.substr(e.url.indexOf('#'))
	}
    }
    return sign;
}

1reaction
EdJoPaTocommented, Oct 4, 2019

In order to detect its an answer the library currently checks for the reply_to_message. It has to have the exact text as questionText provided on startup.

As this check of the replied message is done on every message coming in it is performance critical.

Also when the result of the function would change between the user hitting the button and the response of the user the library would not be able to detect the users reply at all. the user would be stuck. This is why I chose to prefer an always the same questionText.

The menu in general uses the callback_data which allows this library to be stateless (the only states are from the Telegram and the functions asking or the state (like hide)). Normal Text messages do not allow for this kind of statelessness which makes them feel wrong in the context of this library. 😔

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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