I've tried unsuccessfully to to send a message to a private Telegram channel with the following code.
I've double-checked the following
1. the bot is an admin with post message permission
2. bot token is correct
3. chat id is correct.
When execution reaches line If j.Success Then
The error log shows:
Could someone kindly help me to make it work, please?
TIA
I've double-checked the following
1. the bot is an admin with post message permission
2. bot token is correct
3. chat id is correct.
B4X:
Sub SendMsgToPrivateChannel
Dim token As String = "1234567890:ABCDEF1R0-gtm1oBBi0ABCDEFGHIJkLMopr" 'Replace with your actual bot token
Dim chatID As String =""-1001234567890" ' Replace with your actual private channel ID
Dim messageText As String = "Hello world!"
Dim url As String = $"https://api.telegram.org/bot${token}/sendMessage"$
Dim params As Map
params.Initialize
params.Put("chat_id", chatID)
params.Put("text", messageText)
Dim j As HttpJob
j.Initialize("SendTelegram", Me)
j.PostMultipart(url, params, Null)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log("✅ Test message sent successfully.")
ToastMessageShow("Test message sent successfully!", True )
Else
Log("❌ Error sending message: " & j.ErrorMessage)
ToastMessageShow("Failed to send message: " & j.ErrorMessage, True)
End If
j.Release
End Sub
When execution reaches line If j.Success Then
The error log shows:
ResponseError. Reason: , Response:
Could someone kindly help me to make it work, please?
TIA