I was tired of sending me alerts via mail so I created a function to send me messages via telegram.
Telegram is a messenger like WhatsApp, but it has a API through you can send messages directly to your telegram and so to your phone.
Here is the code with two functions. One is the main function (Telegram_MsgBox) to send messages to telegram the other is just for the first setup. (an easy click-through to get the Bot Token and the Chat ID)
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
RandomVariable = sting with variable: %A_OSType%
Telegram_MsgBox(16,1,"string") ;icon before text
Telegram_MsgBox(32,2,RandomVariable) ;icon after text
Telegram_MsgBox("%F0%9F%8E%88",2,RandomVariable) ;own icon
Telegram_MsgBox(0,a,"string with space") ;no icon
Telegram_MsgBox(Option,EmojiPosition,Text)
{
TelegramBotToken =
TelegramBotChatID =
if TelegramBotChatID =
Telegram_FirstCFG()
if TelegramBotChatID =
Telegram_FirstCFG()
if Option=16
TelegramIconString := "%E2%9D%8C"
if Option=32
TelegramIconString := "%E2%9D%94"
if Option=48
TelegramIconString := "%E2%9A%A0%EF%B8%8F"
if Option=64
TelegramIconString := "%E2%84%B9%EF%B8%8F"
IfInString, Option, `%
TelegramIconString := Option
IfLessOrEqual, EmojiPosition, 1
Text = %TelegramIconString% %Text%
IfGreaterOrEqual, EmojiPosition, 2
Text = %Text% %TelegramIconString%
loop 3
{
UrlDownloadToFile https://api.telegram.org/bot%TelegramBotToken%/sendmessage?chat_id=%TelegramBotChatID%&text=%Text%, %A_ScriptDir%\check.rups
sleep 1000
ifexist %A_ScriptDir%\check.rups
{
break
}
if A_index = 3
{
MsgBox, 16,, something went wrong with sending
}
}
filedelete %A_ScriptDir%\check.rups
}
Telegram_FirstCFG()
{
msgbox open telegram and open a new Chat with @botfater`nif yout dont know how you do that, search in your default serach engine for "Telegram Botfather first bot"`n`nyou need to choose a unique name (you cant change it)
loop
{
InputBox, BotToken, enter the in telegram indicated bot token,
MsgBox, 4, , Bot Token correct?:`n%BotToken%
IfMsgBox Yes
break
}
Random, SecurityCode, 1000, 9999
msgbox now open a new chat with your new created bot (search for @*yourbotname* and start a new chat) and enter this number %SecurityCode% and send it via telegram`n press OK, when done.
UrlDownloadToFile https://api.telegram.org/bot%BotToken%/getupdates , %A_ScriptDir%\findChatID.txt
sleep 2000
run %A_ScriptDir%\findChatID.txt
msgbox now search for the number %SecurityCode% and on the same line there should be something like: "chat":{"id":782163891`n`nfound it? press ok
InputBox ChatID, enter the number after "chat":{"id": here:
FileAppend, Telegram Bot Token = %BotToken%`n, %A_ScriptDir%\TokenAndID.txt
FileAppend, Telegram Chat ID = %ChatID%, %A_ScriptDir%\TokenAndID.txt
run %A_ScriptDir%\TokenAndID.txt
msgbox here you go. copy and past the values to the variables TelegramBotToken & TelegramChatID in the sourcecode.`n`n(you can delte all the .txt files)
exitapp
}
Telegram_MsgBox(Option, EmojiPosition, Text)
Option
Sorry for my bad English.