DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,864 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

πŸ‘‹ Hey, my name is Noah and I’m the one who set up this ad. My job is to get you to join DEV, so if you fancy doing me a favor, I’d love for you to create an account.

If you found DEV from searching around, here are a couple of our most popular articles on DEV: