Hello
I thought id share this example i have worked out for posting a message or image with message to the Telegram API. You will need a Telegram bot first and the ID of the chat, all very straightforward to do. Then put one of the snippets below in and Invoke Code activity using Powershell as the language
#Sending a message to Telegram with emojis, setup your Telegram bot first and have the chat ID
$botToken = "YOURBOTTOKEN" #add your own token here
$chatId = "-YOURCHATID" #add your chat ID to post to here
$message = "Message sent! 🎉😊🚀" #add the message you want to send here, you can use emojis too
# Create a dictionary for the form data
$formDict = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]'
$formDict.Add("chat_id", $chatId)
$formDict.Add("text", $message)
# Create the encoded form content
$formData = [System.Net.Http.FormUrlEncodedContent]::new($formDict)
# Send the request
$httpClient = [System.Net.Http.HttpClient]::new()
$response = $httpClient.PostAsync("https://api.telegram.org/bot$botToken/sendMessage", $formData).Result
# Output the response
$response.Content.ReadAsStringAsync().Result
and for an image
# Sending an image with a caption to the Telegram API
$botToken = "YOURTOKEN"
$chatId = "-YOURCHATID"
$message = "Here is your image message 😊"
$imagePath = "YOURIMAGEPATH"
# Create multipart form data
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
# Add chat_id and caption as string content
$multipartContent.Add((New-Object System.Net.Http.StringContent($chatId)), "chat_id")
$multipartContent.Add((New-Object System.Net.Http.StringContent($message)), "caption")
# Add the image as file content
$fileStream = [System.IO.FileStream]::new($imagePath, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read)
$fileContent = New-Object System.Net.Http.StreamContent($fileStream)
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("image/jpeg")
$multipartContent.Add($fileContent, "photo", [System.IO.Path]::GetFileName($imagePath))
# Send the request using HttpClient
$httpClient = [System.Net.Http.HttpClient]::new()
$response = $httpClient.PostAsync("https://api.telegram.org/bot$botToken/sendPhoto", $multipartContent).Result
# Output the response
$response.Content.ReadAsStringAsync().Result
# Clean up: dispose of the stream and client
$fileStream.Dispose()
$httpClient.Dispose()