DEV Community

Cover image for Send a Telegram message with Darklang
Christian
Christian

Posted on • Originally published at cri.dev

2 2

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

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay