If you would like to send messages via Telegram4MQL you need to find out chat IDs of your message targets. Those might be private chats, group chats or channels.
Requirements:
- You need to create a bot (not handled here as there are many useful tutorials out there).
- Start a conversation with your bot
- For private chats: Search your bot in the global contact list, hit /start and maybe send a second message, content does not matter.
- For group chats: Invite your bot as a member into a new or existing group via global contact search. You might enable “privacy mode” to receive more types of messages. See the Telegram documentation for more information. Then send a message.
- For channels: If you just want to receive messages you need to invite your bot as a member into the channel. If you would like to send messages to the channel you need to add the bot as administrator. Then send a message.
When this is done you need to receive these message to detect the chat IDs. In the simplest scenario you enter a URL like this into your browsers address field:
https://api.telegram.org/bot/getUpdates
This will give you a JSON output you can investigate. What you’re looking for ist the <ID> in the following examples (in private chats the private id is the same as the chat id):
Private:
{ "update_id": 146878178, "message": { "message_id": 1352, "from": { "id": <PRIVATE ID>, "first_name": "stzzzzz", "username": "stzzzzz" }, "chat": { "id": <ID>, "first_name": "stzzzzz", "username": "stzzzzzz", "type": "private" }, "date": 1486291815, "text": "some text here with a url https://123.com", "entities": [ { "type": "url", "offset": 0, "length": 44 } ] } }
Group:
{ "update_id": 146878181, "message": { "message_id": 1353, "from": { "id": <PRIVATE ID>, "first_name": "stzzzzz", "username": "stzzzzz" }, "chat": { "id": <ID>, "title": "MQL Group", "type": "group", "all_members_are_administrators": true }, "date": 1486296142, "group_chat_created": true } }
Channel:
{ "update_id": 146xxx, "channel_post": { "message_id": 2, "chat": { "id": <ID>, "title": "testing channel", "type": "channel" }, "date": 1486292382, "text": "test" } }
Ok. You’re ready to use the Telegram4MQL functions now. Have a look.
No Comments »