Template for Sending Messages to Telegram

Hi, I made a robot for sending message to Telegram. I know you can just use notifier, but I use to an HTTPS POST Request, which would come handy for someone that want to use more features from Telegram. For the HTTPS Request you need a .pem certificate to achieve the communication with Telegram servers. In here you can find more information about it.

*** Settings ***
Documentation   Template robot for sending POST Request to Telegram
Library         RPA.Robocloud.Secrets
Library         RPA.Notifier
Library         RPA.HTTP

*** Variables ***
${chat_id}    123456789
${text}       Here goes the message from post, sended from Robocorp Lab
&{data}=      chat_id=${chat_id}    text=${text}

*** Tasks ***
Send Message to Telegram
   #Get the token from my vault.json which location is configured in devdata/env.json
   ${token}=    Get Secret    Telegram

   # Using Notify is far more easier
   Notify Telegram    Text send from Robocorp Lab    ${chat_id}    ${token}[Token]
    
   # Using a post request, more complicated, but, if you want to use more features from telegram this template will work
   Create Session    alias=Telegram    url=https://api.telegram.org   headers={"Content-Type": "application/json", "Host": "api.telegram.org"}     timeout=5    verify=${CURDIR}${/}telegram_certificate.pem
   Post Request      alias=Telegram    uri=bot${token}[Token]/getMe
   Post Request      alias=Telegram    uri=bot${token}[Token]/sendMessage    json=${data}
4 Likes