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 = "" ++ bot_token ++ "/sendMessage"
let query = {
chat_id : chat_id
text : event.text
parse_mode : "HTML"
HttpClient::getv4 url query {}

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"

This is how the worker looks like:

dark telegram