Giter Club home page Giter Club logo

Comments (4)

mildsunrise avatar mildsunrise commented on May 25, 2024 2

ForceReply is intended for groups. Bots that have privacy mode enabled won't be able to see simple text messages (i.e. «Option1») unless those messages are a reply for the bot. By forcing a reply, you ensure the bot will get the message.

That's probably why ForceReply only works on groups. If you're in a direct chat, forcing a reply is pointless since you'll get the text, whether you use it or not.

So, your initial snippet works as expected on a group (screenshot of Telegram Desktop):

group bot example

Note: The const { id } = msg.user; line crashes on a group, you should use msg.chat or msg.from unless you're sure it's a user.

Note: Remember to remove the keyboard when it's no longer needed by doing .keyboard(), i.e.:

reply.keyboard().text(`Bot replying to a forced reply...`);

See the hasher.js example for more info.

from botgram.

mildsunrise avatar mildsunrise commented on May 25, 2024 1

But all of this is irrelevant for mantaining flow; you don't need ForceReply or anything for that.

For info about maintaining flow, see the end of this section and the hasher.js example. (Note that in a real application, you'd use a DB instead.)

from botgram.

HemalR avatar HemalR commented on May 25, 2024

Ok so, reading the docs, I came across: https://core.telegram.org/bots/api#sendmessage where it mentions the keyboard and force reply clash.

Then tried some adjusted code where the keyboard is removed beforehand...

bot.callback((query, next)=>{
	if (query.data === 'Matched string') {
		const { id } = query.message.user;
		const reply = bot.reply(id);
		reply.keyboard(); //Removing this line still doesn't work, see update below
		reply.text('What is the reply to this message?').forceReply();
	} else {
		return next()
	}
});

Still no luck. I suspect it may be because you can only send a single 'reply' via the bot callback (because sending a query.answer after a reply also throws an error). Hmmm...

Update - just tried removing the custom keyboard from all the code entirely, still no-go...

from botgram.

HemalR avatar HemalR commented on May 25, 2024

Ah got it, that explains that.

Read and forgot about the whole context object when going through the docs. Poor effort on my part.

It will work perfectly in conjunction with a database.

Cheers @jmendeth !!

from botgram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.