sending direct messages from nodejs script to telegram - node.js

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)

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:
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
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 )

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

Related

Discord bot that sends messages recieved from webhook

I am trying to make something that will send a notification to my phone via discord when a webhook is called. The notification should have a body of text, and could be something like a python error, or just some plain simple text like "hi there".
I built a discord bot that uses an overridden python BaseHTTPRequestHandler, running in its own thread, which sends the server messages via client.loop.create_task(self.get_channel_by_name(name).send(message)). However, it is pretty slow (takes a few seconds to half a minute to go from webhook to server message, when it really should be almost instantaneous)
I'm thinking I have taken the wrong roundabout method for building my webhook discord server, but I have no idea the right way to go about this, and though I would ask the community. Any thoughts on how to go from requesting a specific file like "http://localhost:8000/post/category/channel/encoded-message", to the specified message in my discord server in a specific channel in a given category? Thanks for any advice!
I figured it out after a bit of googling. Here[https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types] is the discord api for creating bots using webhooks. The trick is you go to the channel of the server you want to send messages to, and in the settings, add a webhook in the intergration tab. No need to mess around with the discord python package. I managed to start sending messages using python requests library, and nothing else.
import requests
requests.post(f'https://discord.com/api/webhooks/{webhook.id}/{webhook.token}', data={'content':message})

is there a method to take screenshots of telegram chat?(want to make a telegram chat screenshot taker)

I am currently writing a bot to take screenshots of Telegram chat in Python.
I have written the options the bot is supposed to give to the user when it's started but I have no idea how to do this.
is it possible at all?
does telegram even let us do such a thing?
Based on official Documents of Telegram :
Bots are no different from human users that you meet in groups for example. They can see your public name, username, and profile pictures, and they can see messages you send to them, that's it.
and you can find more information from bots-privacy-mode
so basically Telegram doesn't let BOTs do such things as taking screenshots.

Telegram different between getUpdates and Webhooks

id like to start using telegram bot, i already read the documentation, but still can't get my head, what's the difference between "getUpdates" and "webhooks"
source: telegram docs
can someone explain this in plain language
thanks in advance
The difference between "getupdates" and "webhook" is just like the difference between pull and push!
Using "getupdates" you don't even need to have a sever! You call telegram server prodically by providing bot's token and it will send you new updates if there is any. It means that your bot is always busy calling telegram even if there is just a single update per your 1000 requests!!
Using "webhook", you first notify telegram about your server ip and listening port and your public key. Then telegram will call your sever whenever there is any update.
At last and not the least If you want your bot to be faster you should use webhook.
Two method can get same content, but you can only use one of them at same time.
Webhook is dependent on HTTPS server, usually use in PHP.
If you haven't a web interface, better to choose getUpdates, which doesn't required HTTPS address to receive updates.

How to read a message from a bot via telegram API?

I have a room with a couple of bots, one of them needs to read all the messages on the room including other bot's messages.
Telegram API says bots can't see other bots message otherwise they might get caught in a "loop".
Since i really need to work around this i'm wondering if there is a known workaround?
There cannot be any workaround using the Bot APIs since the messages in getUpdates or webhook of the Bot will be from Users alone.
One workaround could be to use the telegram-cli and create a normal user as a Bot.

Is it possible for a Telegram Bot to send any type of message without users trigger?

So I need my Telegram bot to ask a question from user (send any message of any possible type) without any initiation from a user. Is it possible? I cant find anything about this.
If the user interacted with your bot before you just need to use their user_id and send your message. You can't however send message to a user who has never interacted with your bot.
Telegram BOT never can take an action before user interact with bot. because most of available method need "chat_id". if you dont have "chat_id", you can only run simple method like getMe, getUpdates,etc.

Resources