sending direct messages from nodejs script to telegram
Asked Answered
G

2

9

Is it possible to send a message from a node.js server to someone's mobile number or telegram Id directly?

is it possible without using a telegram bot?

I need an API like below:

function sendMessage(senderTelegramId, receiverTelegramId, messageText)
Ganger answered 25/12, 2017 at 5:34 Comment(0)
E
14

In short: No, without a bot no way for now.

Detailed explanation:

In order for you to send users messages on telegram you would need to create your own telegram bot. They have a well documented API which you can read and play around with.

There are 2 things you should know about sending messages to users using telegram bot:

  1. You can't just send random people messages on telegram even if you know their phone number, to send them messages you need to have their chat_id. See how in the docs

  2. To get the chat_id the user must first click the start button that comes up when they open your bot for the first time. Telegram will send you the chat id of that user and you save it for later when you would want to send messages to that user.

There are tons of libraries that makes working telegram bots very easy, it wouldn't take you more than an hour to get started.

I hope this answers the question, feel free to ask further questions, I have made some bots and you can also play around with them to see how it works.

Cheers )

Exemplum answered 2/1, 2019 at 8:31 Comment(0)
J
5

There is actually one more easiest way to send a message to chat

just fetch the URL

https://api.telegram.org/bot[BOT_API_KEY]/sendMessage?chat_id=[MY_CHANNEL_NAME]&text=[MY_MESSAGE_TEXT]

you can find more details here https://xabaras.medium.com/sending-a-message-to-a-telegram-channel-the-easy-way-eb0a0b32968

Jaeger answered 25/1, 2021 at 11:22 Comment(1)
the question is to send message to someone's phone number not channelThirlage

© 2022 - 2024 — McMap. All rights reserved.