DEV Community

Cover image for Send a Telegram message with Darklang
Christian
Christian

Posted on • Originally published at cri.dev

Send a Telegram message with Darklang

Originally posted on cri.dev

In this example you can see how to emit a Worker event with Darklang.

Telegram endpoint /sendMessage

Using the endpoint messages.sendMessage you can simply send a message on Telegram by calling this endpoint via GET and the needed parameters in the query string.

The worker

The worker is named send_telegram_message and looks like this:

let chat_id = "YOUR_CHAT_ID"
let bot_token = "YOUR_BOT_TOKEN"
let url = "https://api.telegram.org/bot" ++ bot_token ++ "/sendMessage"
let query = {
              chat_id : chat_id
              text : event.text
              parse_mode : "HTML"
            }
HttpClient::getv4 url query {}
Enter fullscreen mode Exit fullscreen mode

Calling the worker

The worker is then called with and event body, which should contain the text to send via Telegram:

let event = {
              text: "Hello from Darklang"
            }
let _ emit event "send_telegram_message"
Enter fullscreen mode Exit fullscreen mode

This is how the worker looks like:

dark telegram

Top comments (0)