Hi,
Is it possible to create an autohotkey script to monitor ones internet connection, and if it's lost & then reconnected, send yourself a message via telegram (using a telegram bot) saying for example 'Internet reconnected'.
Please could someone suggest a script? As I've been trying to use my telegram bot ChatID and Bot Token to do this but haven't had any luck.
Thanks in advance
Script to monitor internet connection and send telegram message when internet reconnects?
Re: Script to monitor internet connection and send telegram message when internet reconnects?
These are two separate problems, imho.
I think for checking the internet connection you should find something on these forums.
Sending a message via your Telegram bot didn't work? Then please show your code.
(Of course, remove your personal and bot tokens/IDs first; I can use my own.)
I think for checking the internet connection you should find something on these forums.
Sending a message via your Telegram bot didn't work? Then please show your code.
(Of course, remove your personal and bot tokens/IDs first; I can use my own.)
Re: Script to monitor internet connection and send telegram message when internet reconnects?
In case this helps with the "network connect" part: Windows Task Scheduler can actually detect that event. You could then set it to run your script.
Re: Script to monitor internet connection and send telegram message when internet reconnects?
Thanks, mikeyww. I wasn't aware.
MDean1201, it also appears we discussed the internet (re-)connection part already in 2018: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=50243
MDean1201, it also appears we discussed the internet (re-)connection part already in 2018: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=50243
Re: Script to monitor internet connection and send telegram message when internet reconnects?
So I did create an check internet script in the past. However it is a bit clunky, and was wondering if there was a more efficient way to continually check the internet, until the internet reconnects:
And this is my telegram script which doesnt seem to work at all. So if someone could advise on how to get this to work, I would really appreciate it
Code: Select all
UrlDownloadToVar(URL) {
ComObjError(false)
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", URL)
WebRequest.Send()
Return WebRequest.ResponseText
}
#Persistent
SetTimer, CheckInternet, 500
Return
CheckInternet:
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{}
else
{
MsgBox,, Title:Internet status, Text:first check = not working will check again in 2mins & send message, 1
sleep, 25000
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{
MsgBox,, Title:Internet status, Text:2nd check = working, 5
Run "C:\Users\X\Desktop\telegram send.ahk"
Sleep, 2000
Process, Close, testprogram.exe
Sleep, 2000
Run c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
Sleep, 2000
Send, "C:\Users\X\Documents\testprogram.exe"
Sleep, 2000
Send, {Return}
Return
}
Else
MsgBox,, Title:Internet status, Text:2nd check = not working, 5
sleep, 25000
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{
MsgBox,, Title:Internet status, Text:3RD check = working, 5
Run "C:\Users\X\Desktop\telegram send.ahk"
Sleep, 2000
Process, Close, testprogram.exe
Sleep, 2000
Run c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
Sleep, 2000
Send, "C:\Users\X\Documents\testprogram.exe"
Sleep, 2000
Send, {Return}
Return
}
else
MsgBox,, Title:Internet status, Text:3rd check = not working, 5
Sleep, 25000
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{
MsgBox,, Title:Internet status, Text:4th check = working, 5
Run "C:\Users\X\Desktop\telegram send.ahk"
Sleep, 2000
Process, Close, testprogram.exe
Sleep, 2000
Run c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
Sleep, 2000
Send, "C:\Users\X\Documents\testprogram.exe"
Sleep, 2000
Send, {Return}
Return
}
else
MsgBox,, Title:Internet status, Text:5th check = not working, 5
Sleep, 25000
html := UrlDownloadToVar("http www.google.com ") Broken Link for safety
if html
{
MsgBox,, Title:Internet status, Text:5th check = working, 5
Run "C:\Users\X\Desktop\telegram send.ahk"
Sleep, 2000
Process, Close, testprogram.exe
Sleep, 2000
Run c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
Sleep, 2000
Send, "C:\Users\X\Documents\testprogram.exe"
Sleep, 2000
Send, {Return}
}
else,
Return
}
Code: Select all
chatid :=
text := "test message"
param := "chat_id=" chatid "&text=" text
str =https api.telegram.org /botXXXXXXX/sendmessage? Broken Link for safety ;
;msgbox, % url_tovar(str, param) ; this is useful if you need to return data
url_tovar(str, param)
url_tovar(URL, param) {
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", URL)
WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
WebRequest.Send(param)
res := WebRequest.ResponseText
return res
}
Re: Script to monitor internet connection and send telegram message when internet reconnects?
This works for me, if I add my chat ID and bot token at the top:
Code: Select all
chatid := 1234567890 ; <--- change
botToken := "mybotToken" ; <--- change
text := "test message"
param := "chat_id=" chatid "&text=" text
str := "https://api.telegram.org/bot" botToken "/sendmessage?"
; msgbox % url_tovar(str, param)
url_tovar(str, param)
url_tovar(URL, param) {
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", URL)
WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
WebRequest.Send(param)
res := WebRequest.ResponseText
return res
}
Re: Script to monitor internet connection and send telegram message when internet reconnects?
thanks for the help. So I tried the script you suggested, however I got these messages when I ran the script (and I tried uncommenting the line wih msgbox)
Any idea how I can fix this?
Any idea how I can fix this?
Re: Script to monitor internet connection and send telegram message when internet reconnects?
Probably has to do with the TLS settings on your computer - as was discussed here: https://www.autohotkey.com/boards/viewtopic.php?t=58051 which probably can be fixed via registry edits (I assume, you already re-started your computer since this error occurred for the first time).
Since I have never encountered this problem personally, I can't give you a better lead at the moment... I have some Telegram bots running now for years, currently on a recent Win10 version. Are you using something older, like Win7 ?
Since I have never encountered this problem personally, I can't give you a better lead at the moment... I have some Telegram bots running now for years, currently on a recent Win10 version. Are you using something older, like Win7 ?
Re: Script to monitor internet connection and send telegram message when internet reconnects?
thanks @gregster
I think it is indeed something to do with the TLS settings. I looked through the thread you referenced and tried the various suggestions, including SKANs, but to no avail.
I'm running windows 7 still for various reasons.
Think I might have to give up on this one, but thank you for your help.
I think it is indeed something to do with the TLS settings. I looked through the thread you referenced and tried the various suggestions, including SKANs, but to no avail.
I'm running windows 7 still for various reasons.
Think I might have to give up on this one, but thank you for your help.
Re: Script to monitor internet connection and send telegram message when internet reconnects?
I see.
Not sure if it will cause the same problem for you, but this also works for me:
(The tempfile you could save anywhere, and delete afterwards.)
Not sure if it will cause the same problem for you, but this also works for me:
Code: Select all
chatid := 111111111
botToken := "myBotToken"
text := "test"
param := "chat_id=" chatid "&text=" text
str := "https://api.telegram.org/bot" botToken "/sendmessage?"
UrlDownloadToFile, % str . param, tempfile.txt
Who is online
Users browsing this forum: CaseyMoon, Google [Bot], imstupidpleshelp, mmflume and 171 guests