B4J Code Snippet sendPhoto with telegram

:oops: Can't try it with httpjob, so use curl instead, because raspberry pi/linux can also use this command :rolleyes:

B4X:
    Dim url As String = $"https://api.telegram.org/bot${pToken}/sendPhoto"$  
    Dim shl As Shell
    shl.Initialize("TeleImage", "curl.exe", Array As String(url,"-F",$"chat_id=${chatid}"$,"-F",$"photo=@${imgDir}\${imgName}"$))
    shl.WorkingDirectory = File.DirApp
    shl.Run(-1)
 
Last edited:

jinyistudio

Well-Known Member
Licensed User
Longtime User
Instead, use this...




sendphoto url:
    '傳送圖片
    Log("傳送圖片==>")
    Dim now As Long
    DateTime.DateFormat= "yyyyMMdd HH:mm"
    now = DateTime.Now

    msg = "圖片發送 " & DateTime.Date(now)
   
    Dim m1 As Map '= CreateMap("chat_id":chat_id,"text":msg)
    m1.Initialize
    m1.Put("chat_id",chat_id)
    m1.Put("text",msg)
    m1.Put("photo","https://js.pngtree.com/web3/images/logo.png")
   
    m1.Put("parse_mode","HTML")
    'm1 = CreateMap("chat_id":chat_id,"text":msg)
   
    Dim sb As StringBuilder
    Dim lc_query As String
   
    sb.Initialize
    lc_query = ""
    For i=0 To m1.Size-1
        If i > 0 Then
            sb.Append("&")
        End If
       
        sb.Append(m1.GetKeyAt(i) )
        sb.Append("=" )
        sb.Append(m1.GetValueAt(i) )
       
       
    Next
    lc_query = sb.ToString
   

    url = $"https://api.telegram.org/bot${token}/sendPhoto?${lc_query}"$
    Log("url= "&url)
   
    j.Download(url)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
       
        Dim m1 As Map
        Dim json As JSONParser
       
        json.Initialize(j.GetString)
        m1 = json.NextObject
        If (m1.Get("ok"))==True Then
           
            xui.MsgboxAsync("OK","info")
        End If
       
    End If
It is ok but It cann't send local disk image file.
 
Top