0

Greeting, I need support to do this with example or exact code as I'm lost and don't know a bit about sending

Function VBA2Telegram(token As String, ChatID As String)
Dim msg1 As String, PostMsgStr As String, PhotoPath As String,sUrl As String
Dim oHttp As Object, sHTML As String, PostPhotoStr As String, strPostData As String

msg1 = "Hello there"
PhotoPath = "C:\1123.jpg"
PostMsgStr = "https://api.telegram.org/bot" & token & "/sendMessage?chat_id=" & ChatID & "&text=" & msg1
PostPhotoStr = "https://api.telegram.org/bot" & token & "/sendPhoto?chat_id=" & ChatID & "&photo=" & PhotoPath

Set oHttp = CreateObject("MSXML2.XMLHTTP")

oHttp.Open "POST", PostMsgStr, False
oHttp.Send

'Here,, how to set the code to do the job of sending local photo to telegram!
oHttp.Open "POST", PostPhotoStr, False
oHttp.Send

sHTML = oHttp.ResponseText
Debug.Print sHTML

End Function
Adnan Al-Husain
  • 110
  • 1
  • 3
  • 17

1 Answers1

0

To upload a photo which is in your machine, you cannot use the GET method for the request with the path of your file, instead you should POST a form in multipart/form-data fashion with the content of the file: see the documentation.

You can search how to use multipart/form-data in vba. This link or stack overflow answer may help you as well.

Ali Khalili
  • 1,504
  • 3
  • 18
  • 19
  • Thanks brother for you support and reply. I've read about multipart/form-data and couldn't test it as all examples I saw were about uploading to a web and telegram has different parameters.. also the bounary I couldn't know what is it and how to use it. other than the converting to binary. that's why I asked for clear example to send to telegram. – Adnan Al-Husain May 20 '20 at 23:35