Created
August 6, 2019 07:26
-
-
Save dimiboy/1737878ab1a093e3d3f20594a2ba2d1a to your computer and use it in GitHub Desktop.
Telegram listener via Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Edit only this part! ################ | |
$MyToken = "" | |
$ChatID = "" | |
######################################### | |
$InitialMessageDate = 0 | |
$counter = 0 | |
while ($true) | |
{ | |
$MyBotUpdates = Invoke-WebRequest -Uri "https://api.telegram.org/bot$($MyToken)/getUpdates" | |
#Convert the result from json and put them in an array | |
$jsonresult = [array]($MyBotUpdates | ConvertFrom-Json).Result | |
$LastMessage = "" | |
#write-host "before loop $InitialMessageDate" | |
Foreach ($Result in $jsonresult) { | |
#write-host "$Result.update_id[-1]" | |
If (($Result.channel_post.chat.id -eq $ChatID) -AND ($Result.update_id -gt $InitialMessageDate)) { | |
if(($LastMessage -ne $null) -AND ($counter -gt 0)){ | |
powershell $Result.channel_post.text | |
} | |
$LastMessage = $Result.channel_post.text | |
} | |
} | |
$InitialMessageDate = $jsonresult.update_id[-1] | |
sleep 1 | |
$counter++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment