dEEpEst
☣☣ In The Depths ☣☣
Staff member
Administrator
Super Moderator
Hacker
Specter
Crawler
Shadow
- Joined
- Mar 29, 2018
- Messages
- 13,861
- Solutions
- 4
- Reputation
- 27
- Reaction score
- 45,549
- Points
- 1,813
- Credits
- 55,350
7 Years of Service
56%
Send messages to a Telegram chat via Powershell
Bash:
# Replace with your actual Telegram Bot Token and Chat ID
$token = "<your_token>"
$chatId = "<chat_id>"
# The message you want to send
$message = "Hello from PowerShell!"
# Construct the URL for the Telegram Bot API sendMessage method
$url = "https://api.telegram.org/bot$token/sendMessage"
# Prepare the parameters (body) to be sent as form data
$body = @{
chat_id = $chatId
text = $message
}
# Using Try-Catch for error handling
try {
# Send the POST request to the Telegram API endpoint
$response = Invoke-RestMethod -Uri $url -Method Post -Body $body
# Output the response from the server
Write-Output "Message sent successfully:"
Write-Output $response
} catch {
# Handle any errors that occur during the request
Write-Error "An error occurred sending the message: $_"
}