Powershell snippet to send messages to telegram

* Powershell snippet to send messages to telegram:


[source,powershell]
------------------------------------------------------------------------------------
# send am message to telegram chat via powershell script
# ======================================================

$api    = '20****xw4'    # botToken got with bot creation 
$chatId = '8***8'            # got with query on bot chat
$msg    = 'Hello from powershell (server)'


$restResponse = Invoke-RestMethod -Uri ('https://api.telegram.org/bot{0}/sendMessage?chat_id={1}&text={2}' -f $api, $chatId, $msg) -Proxy http://193.**.***.207:8080

$restResponse.ok # True
------------------------------------------------------------------------------------


* create telegram chat to send messages to:

** Create the Bot and get the token

- open a chat with BotFather Bot.
- write /newbot to BotFather,
        - fill all the needed information, write down the botToken (for $api)

** Create the destination chat and get the chatId

- Open a new chat with your new Bot and post a message on the chat
- Open a browser and invoke https://api.telegram.org/bot/getUpdates (where is the botToken previously obtained)
- Look at the JSON result and write down the value of result[0].message.from.id. That is the chatId.


shamelessly copied from diverse webpages, e.g.
http://blog.dhcgn.de/homematik/telegram/2016/03/08/Telegram-API-mit-Powershell-nutzen.html

Kommentare

Beliebte Posts aus diesem Blog

using the birt runtime with spring boot and gradle to generate PDF from a Report Design File