Ks Tan (Asia Vad) asked a question.

Alert Integrate with Telegram Messaging

VBScript below performs HTTPS post to Telegram server, to send telegram message

Prerequisite:

1. Telegram BOT account, act as member to a Telegram chat group (channel), to post message via script.

2. Two ID: BOT account API_ID, and the unique chat group ID

 

Code sharts here

  1. ‘By Kstan, Asia Vad
  2. ‘Created when new BOT XXX_name is created, enter the token given to access the HTTP API for your BOT
  3. sAPI_ID = "6140647978:ASIAVadGQeAOspF0tMSOcjxGLrLLxtcz7XI"
  4. ‘Enter the Chat_ID, corresponding to your telegram channel here, chat group.
  5. 'Below ID is XXX_AsiaVad_WUGChannel
  6. sChat_ID = "-1001637099131"
  7. ‘Test Message - to comment off
  8. 'Can modify with different WhatsUp Gold percent variables
  9. sMSG = "%Device.DisplayName (%Device.Address) is %Device.State, at %System.Time on %System.Date"
  10.  
  11. 'URL to open....
  12.  
  13. sUrl = "https://api.telegram.org/bot" & sAPI_ID & "/sendMessage"
  14. 'POST Request to send.
  15. sRequest = "text=" & sMSG & "&chat_id=" & sChat_ID
  16.  
  17. HTTPPost sUrl, sRequest
  18.  
  19. Function HTTPPost(sUrl, sRequest)
  20. set oHTTP = CreateObject("Microsoft.XMLHTTP")
  21. oHTTP.open "POST", sUrl,false
  22. oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  23. oHTTP.setRequestHeader "Content-Length", Len(sRequest)
  24. oHTTP.send sRequest
  25. HTTPPost = oHTTP.responseText
  26.  
  27. End Function

 


  • Rhael Sananes (EANA S.E.)

    Hello Jason,

     

      Thank you for your collaboration, I want to ask you, I understand that I must create a Monitor (Active Script Monitor) and replace the variables with mine, and then assign that monitor to the host that I want the alert. Did I understand correctly?

  • Rhael Sananes (EANA S.E.)

    Hi Jason, I was creating the VBscript as shown in the example, generated a simple active monitor and replaced the token and chat id with the one we created, but we have had no luck. I would appreciate it if you have a little more documentation or if you have an example of an active monitor with an example variable: %ActiveMonitor.State

  • Rhael Sananes (EANA S.E.)

    Thanks Jason, I had a comment sign error that prevented me from executing the script.

     

    Thank you so much