Branch | Windows | MacOS | Linux |
---|---|---|---|
main | |||
Enhancements |
PoshGram is a PowerShell module that enables you to send messages via the Telegram Bot API
PoshGram provides functionality to send various message types to a specified Telegram chat via the Telegram Bot API. Separate PowerShell functions are used for each message type. Checks are included to ensure that file extensions, and file size restrictions are adhered to based on Telegram requirements.
Documentation for PoshGram is available at: https://poshgram.readthedocs.io
# from a 6.1.0+ PowerShell session
Install-Module -Name 'PoshGram' -Repository PSGallery -Scope CurrentUser
#------------------------------------------------------------------------------------------------
# import the PoshGram module
Import-Module -Name 'PoshGram'
# set your bot token and chat channel id
$botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx'
$chatID = '-nnnnnnnnn'
#------------------------------------------------------------------------------------------------
# easy way to validate your Bot token is functional
Test-BotToken -BotToken $botToken
#------------------------------------------------------------------------------------------------
# send a basic Text Message
Send-TelegramTextMessage -BotToken $botToken -ChatID $chatID -Message 'Hello'
#------------------------------------------------------------------------------------------------
# get information for a Telegram sticker pack
Get-TelegramStickerPackInfo -BotToken $botToken -StickerSetName STPicard
#------------------------------------------------------------------------------------------------
# get information about Telegram custom emoji stickers using their identifiers (experimental)
Get-TelegramCustomEmojiStickerInfo -BotToken $botToken -CustomEmojiIdentifier 5404870433939922908
#------------------------------------------------------------------------------------------------
# send a contact's information
Send-TelegramContact -BotToken $botToken -ChatID $chatID -PhoneNumber $phone -FirstName $firstName
#------------------------------------------------------------------------------------------------
#send an animated emoji that will display a random value
Send-TelegramDice -BotToken $botToken -ChatID $chatID -Emoji $emoji
#------------------------------------------------------------------------------------------------
# send an animated gif from a local source
Send-TelegramLocalAnimation -BotToken $botToken -ChatID $chatID -AnimationPath $animation
#------------------------------------------------------------------------------------------------
# send an audio message from a local source
Send-TelegramLocalAudio -BotToken $botToken -ChatID $chatID -Audio $audio
#------------------------------------------------------------------------------------------------
# send a file message from a local source
Send-TelegramLocalDocument -BotToken $botToken -ChatID $chatID -File $file
#------------------------------------------------------------------------------------------------
# send a photo message from a local source
Send-TelegramLocalPhoto -BotToken $botToken -ChatID $chatID -PhotoPath $photo
#------------------------------------------------------------------------------------------------
#sends Telegram sticker message from a local source
Send-TelegramLocalSticker -BotToken $botToken -ChatID $chatID -StickerPath $sticker
#------------------------------------------------------------------------------------------------
# send a video message from a local source
Send-TelegramLocalVideo -BotToken $botToken -ChatID $chatID -Video $video
#------------------------------------------------------------------------------------------------
# send a map point location using Latitude and Longitude
Send-TelegramLocation -BotToken $botToken -ChatID $chatID -Latitude $latitude -Longitude $longitude
#------------------------------------------------------------------------------------------------
# sends a group of photos or videos as an album from a local source
Send-TelegramMediaGroup -BotToken $botToken -ChatID $chatID -FilePaths (Get-ChildItem C:\PhotoGroup | Select-Object -ExpandProperty FullName)
#------------------------------------------------------------------------------------------------
# send a poll with a question and options
Send-TelegramPoll -BotToken $botToken -ChatID $chatID -Question $question -Options $opt
#------------------------------------------------------------------------------------------------
#send Telegram sticker with known sticker file_id
Send-TelegramSticker -BotToken $botToken -ChatID $chatID -FileID $sticker
#send Telegram sticker (best effort) with sticker pack name and emoji shortcode
Send-TelegramSticker -BotToken $botToken -ChatID $chatID -StickerSetName STPicard -Shortcode ':slightly_smiling_face:'
#------------------------------------------------------------------------------------------------
# send an animated gif from a URL source
Send-TelegramURLAnimation -BotToken $botToken -ChatID $chatID -AnimationURL $animationURL
#------------------------------------------------------------------------------------------------
# send an audio message from a URL source
Send-TelegramURLAudio -BotToken $botToken -ChatID $chatID -AudioURL $audioURL
#------------------------------------------------------------------------------------------------
# send a file message from a URL source
Send-TelegramURLDocument -BotToken $botToken -ChatID $chatID -FileURL $fileURL
#------------------------------------------------------------------------------------------------
# send a photo message from a URL source
Send-TelegramURLPhoto -BotToken $botToken -ChatID $chatID -PhotoURL $photoURL
#------------------------------------------------------------------------------------------------
#send a sticker message from a URL source
Send-TelegramURLSticker -BotToken $botToken -ChatID $chatID -StickerURL $stickerURL
#------------------------------------------------------------------------------------------------
# send a video message from a URL source
Send-TelegramURLVideo -BotToken $botToken -ChatID $chatID -VideoURL $videoURL
#------------------------------------------------------------------------------------------------
# send information about a venue
Send-TelegramVenue -BotToken $botToken -ChatID $chatID -Latitude $latitude -Longitude $longitude -Title $title -Address $address
#------------------------------------------------------------------------------------------------
###########################################################################
#sending a telegram message from older versions of powershell
###########################################################################
#here is an example of calling PowerShell 6.1+ from PowerShell 5.1 to send a Telegram message with PoshGram
& 'C:\Program Files\PowerShell\6\pwsh.exe' -command { Import-Module PoshGram;$botToken = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx';$chatID = '-nnnnnnnnn';Send-TelegramTextMessage -BotToken $botToken -ChatID $chatID -Message "Test from 5.1 calling 6.1+ to send Telegram Message via PoshGram" }
#--------------------------------------------------------------------------
#here is an example of calling PowerShell 6.1+ from PowerShell 5.1 to send a Telegram message with PoshGram using dynamic variables in the message
$botToken = “#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx”
$chatID = “-#########”
$test = "I am a test"
& '.\Program Files\PowerShell\6\pwsh.exe' -command "& {Import-Module PoshGram;Send-TelegramTextMessage -BotToken $botToken -ChatID $chatID -Message '$test';}"
#--------------------------------------------------------------------------
#here is an example of calling PowerShell 7+ from PowerShell 5.1 to send a Telegram message with PoshGram
& 'C:\Program Files\PowerShell\7\pwsh.exe' -command { Import-Module PoshGram;$botToken = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx';$chatID = '-nnnnnnnnn';Send-TelegramTextMessage -BotToken $botToken -ChatID $chatID -Message "Test from 5.1 calling 7+ to send Telegram Message via PoshGram" }
#--------------------------------------------------------------------------
This PowerShell project was created with Catesta.
If you'd like to contribute to pwshEmojiExplorer, please see the contribution guidelines.
This project is licensed under the MIT License.