0
const chat_id = req.body.message.chat.id
const dharmaraj = 2xx4xxx5x //My Telegram UID

So I have these 2 const declared at top and chat_id is ID of group/user who used my bot command. If I use the bot from my personal chat, it does reply. But when someone else use the bot in private or in group, the bot won't alert me about it in Telegram.

Here is the code:

console.log(`Post command used by ${user_id}`)

 res.status(200).send({
     method: 'sendMessage',
     dharmaraj,
     text: `Message posted successfully!!`,
     parse_mode: 'Markdown'
 })

The console.log() statement does work.

enter image description here

But I don't receive the message from the bot. I have started the bot and have a long chat history as well. So that shouldn't be an issue.

I read this but I don't want to use any other package.

EDIT:

(1) If I replace it with the chat_id itself (ID where the bot was triggered) it will send message in that chat. Problem is to get some text in my personal chat so I know the bot has been used.

(2) I tried embedding the snippet in a try-catch but no error there.

(3) Tried replacing UID with the @username but no luck.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • `dharmaraj` seems to be your ID, you'll still need to tell telegeram thats a chat id: Try something like: `method: 'sendMessage', chat_id: dharmaraj, ...` – 0stone0 May 13 '20 at 10:43
  • @0stone0 it does when I run the command in a group and then it sends message to me. But when I replace my ID with with group ID then the command will run if it is ran in group. It wont get triggered from my personal chat – Dharmaraj May 13 '20 at 11:06
  • So you want the bot to send 2 messages as his reply, one tho the user and one to you? Then you should send a second message, the first to `chat_id` to reply, second to your own id? – 0stone0 May 13 '20 at 11:13
  • @0stone0 I want to use command `/post` from private chat with bot. Then the bot must post the message in the group. – Dharmaraj May 13 '20 at 11:14
  • @0stone0 I replace `dharmaraj` ID with `group_id`... bot has access to messages in group. – Dharmaraj May 13 '20 at 11:14
  • Try editing the question and elaborate it some more, I'm having trouble understanding your real question. – 0stone0 May 13 '20 at 11:19
  • @0stone0 check now. I want the bot to publish a message by running a command in private chat with bot. – Dharmaraj May 13 '20 at 11:23
  • the private chat is a supergroup and bot has access to its messages? (I guess you should explain your question more clear) – Ali Khalili May 14 '20 at 21:11
  • @AliKhalili yes it's a supergroup and anyways as far as I know all groups are supergroups after an update – Dharmaraj May 15 '20 at 03:13

0 Answers0