Eng. Samer T
Eng. Samer T

Reputation: 6526

how to know where user starting chat? from inside group or from inside bot directly?

I have created telegram bot using telegraf.js

The bot is working correctly, however I need to handle a different thing if the user send message from inside bot directly, let's say the bot should replay with help commands documentations (for example).

the question is:

how to recoginze where the user start chatting? from inside chat group or from inside bot directly?

I tried

 var groupInfo =await ctx.telegram.getChat()

without success

I thing the solution would be simple, but I can't find it till now.

thank you in advanced.

Upvotes: 0

Views: 1088

Answers (1)

Ali Padida
Ali Padida

Reputation: 1949

You should checkout Telegram docs for Chat type. It has a field called Type and according to the docs:

Type of chat, can be either “private”, “group”, “supergroup” or “channel”

So in telegraf.js you can check the field this ways:

bot.on('text', (ctx) => {
    return ctx.reply(`Chat type is: ${ctx.message.chat.type}`)
})

In your case, ctx.message.chat.type == "private" would be messages that are sent to your bot privately and ctx.message.chat.type == "group" or ctx.message.chat.type == "supergroup" are messages sent to groups.

Upvotes: 1

Related Questions