Skip to content

Instantly share code, notes, and snippets.

@ajay1685
Created November 1, 2022 14:52
Show Gist options
  • Save ajay1685/598cf8b2afdb08c6e4d3f2215f6754ed to your computer and use it in GitHub Desktop.
Save ajay1685/598cf8b2afdb08c6e4d3f2215f6754ed to your computer and use it in GitHub Desktop.
Telegram alerts from a QuPath script
//use BotFather to create a bot, BotFather can also provide API token for your bot
bot_token="0123456789:AaBcDeFGhxihUjCw6uiE9HED_lLuVy_dummy"
//Start a new chat and add your bot to the chat, get a chat_id for that chat
//More information about chat id at : https://www.alphr.com/find-chat-id-telegram/
new URL("https://api.telegram.org/bot"+bot_token+"/getUpdates").text //find chat id in the response
//use the chat id found above
chat_id= "-123456789"
//send a message like this
telegramNotification(bot_token,chat_id,"This is a test notification from QuPath :)")
def telegramNotification(bot_token,chat_id,message){
new URL("https://api.telegram.org/bot"+bot_token+"/sendMessage?chat_id="+chat_id+"&text="+message)
.getText(connectTimeout: 3000,
readTimeout: 5000,
useCaches: true,
allowUserInteraction: false,
requestProperties: ['Connection': 'close'])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment