0

I wish I could use some macros to send Dashboard summary text over the work Telegram. I know that for me to send by telegram through webhook (GET and POST html) and I researched and found this topic here: How can I send an HTTP POST request to a server from Excel using VBA?

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "https://api.telegram.org/bot<token>/METHOD_NAME"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send("")

Replacing < Token > and < Method_name >

https://core.telegram.org/bots/api

However, when I debug the code it locks up excel and does not come back anymore. Any idea what that might be?

  • Are you actually sending anything in the "" ? it might be sending and not receiving a response so just freezing, waiting for something it's not going to get – jamheadart Jul 07 '17 at 19:26
  • In my view, I do not think I need information in this part of send, because it is something that if I access the link ("https://api.telegram.org/bot/METHOD_NAME") the method is already sending Something, the proof that if I play this in the browser I get a message in string. – Alberto Vitoriano Jul 07 '17 at 19:33
  • is it definitely a POST request you need then and not a GET request? – jamheadart Jul 08 '17 at 16:47
  • Returns the same error using GET and POST – Alberto Vitoriano Jul 10 '17 at 19:20
  • 1
    Try changing the False in the `objHTTP.open "POST", URL, False` to True, to make it asynchronous send. If it still freezes then the error might be deeper than a code problem. You should also try an MSXML2.ServerHTTP60 object to send your requests instead of `ServerXMLHTTP`, that means you can set timeouts for your requests, might be useful for testing. – jamheadart Jul 10 '17 at 20:40
  • It worked when I used ServerHTTP60 – Alberto Vitoriano Jul 11 '17 at 12:12

1 Answers1

2

It worked when I deployed MSXML2.ServerXMLHTTP to MSXML2.ServerHTTP60.

Sub fff()

Set objHTTP = CreateObject("MSXML2.ServerHTTP60")
URL = "https://api.telegram.org/bot<token>/sendMessage?chat_id="id"&text=test"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ("")

Cells(1, 1).Value = objHTTP.ResponseText

End Sub