Skip to content

Repository files navigation

PoshGram

Minimum Supported PowerShell VersionPowerShell GalleryCross PlatformLicenseDocumentation Status

PoshGram Logo

BranchWindowsMacOSLinux
mainBuild StatusAppVeyor Build statusBuild Status
EnhancementsBuild StatusAppVeyor Build statusBuild Status

Synopsis

PoshGram is a PowerShell module that enables you to send messages via the Telegram Bot API

Description

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.

Features

  • Versatile Messaging: Send a wide variety of message types, including text, contact, dice, animation, audio, document, photo, sticker, video, location, multi-media, poll, and venue messages. It also supports HTML and Markdown for rich text formatting.
  • Interactive Elements: Incorporate custom keyboards and inline buttons to make your messages interactive. Sticker Info**: Easily query sticker packs, get sticker information, and send stickers directly through PowerShell commands.
  • Notification Control: Opt to send messages silently or with notifications.
  • Content Protection: Enable features to protect messages from being forwarded or saved.
  • Flexible Application: Use in various scenarios like integrating with task schedulers, alert systems, serverless functions, or automating chat responses.
  • User-Friendly Experience: PoshGram is designed for easy use, suitable for PowerShell users at various skill levels. It offers a simpler way to leverage Telegram's messaging features, combining straightforward cmdlets with clear documentation, ideal for enhancing PowerShell tasks with Telegram's capabilities.

Getting Started

Documentation

Documentation for PoshGram is available at: https://poshgram.readthedocs.io

Prerequisites

  • PowerShell 6.1.0 (or higher version)
  • Telegram requirements

Installation

# from a 6.1.0+ PowerShell sessionInstall-Module-Name 'PoshGram'-Repository PSGallery -Scope CurrentUser

Quick start

PoshGram Gif Demo

#------------------------------------------------------------------------------------------------# import the PoshGram moduleImport-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 functionalTest-BotToken-BotToken $botToken#------------------------------------------------------------------------------------------------# send a basic Text MessageSend-TelegramTextMessage-BotToken $botToken-ChatID $chatID-Message 'Hello'#------------------------------------------------------------------------------------------------# get information for a Telegram sticker packGet-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 informationSend-TelegramContact-BotToken $botToken-ChatID $chatID-PhoneNumber $phone-FirstName $firstName#------------------------------------------------------------------------------------------------#send an animated emoji that will display a random valueSend-TelegramDice-BotToken $botToken-ChatID $chatID-Emoji $emoji#------------------------------------------------------------------------------------------------# send an animated gif from a local sourceSend-TelegramLocalAnimation-BotToken $botToken-ChatID $chatID-AnimationPath $animation#------------------------------------------------------------------------------------------------# send an audio message from a local sourceSend-TelegramLocalAudio-BotToken $botToken-ChatID $chatID-Audio $audio#------------------------------------------------------------------------------------------------# send a file message from a local sourceSend-TelegramLocalDocument-BotToken $botToken-ChatID $chatID-File $file#------------------------------------------------------------------------------------------------# send a photo message from a local sourceSend-TelegramLocalPhoto-BotToken $botToken-ChatID $chatID-PhotoPath $photo#------------------------------------------------------------------------------------------------#sends Telegram sticker message from a local sourceSend-TelegramLocalSticker-BotToken $botToken-ChatID $chatID-StickerPath $sticker#------------------------------------------------------------------------------------------------# send a video message from a local sourceSend-TelegramLocalVideo-BotToken $botToken-ChatID $chatID-Video $video#------------------------------------------------------------------------------------------------# send a map point location using Latitude and LongitudeSend-TelegramLocation-BotToken $botToken-ChatID $chatID-Latitude $latitude-Longitude $longitude#------------------------------------------------------------------------------------------------# sends a group of photos or videos as an album from a local sourceSend-TelegramMediaGroup-BotToken $botToken-ChatID $chatID-FilePaths (Get-ChildItem C:\PhotoGroup |Select-Object-ExpandProperty FullName)
#------------------------------------------------------------------------------------------------# send a poll with a question and optionsSend-TelegramPoll-BotToken $botToken-ChatID $chatID-Question $question-Options $opt#------------------------------------------------------------------------------------------------#send Telegram sticker with known sticker file_idSend-TelegramSticker-BotToken $botToken-ChatID $chatID-FileID $sticker#send Telegram sticker (best effort) with sticker pack name and emoji shortcodeSend-TelegramSticker-BotToken $botToken-ChatID $chatID-StickerSetName STPicard -Shortcode ':slightly_smiling_face:'#------------------------------------------------------------------------------------------------# send an animated gif from a URL sourceSend-TelegramURLAnimation-BotToken $botToken-ChatID $chatID-AnimationURL $animationURL#------------------------------------------------------------------------------------------------# send an audio message from a URL sourceSend-TelegramURLAudio-BotToken $botToken-ChatID $chatID-AudioURL $audioURL#------------------------------------------------------------------------------------------------# send a file message from a URL sourceSend-TelegramURLDocument-BotToken $botToken-ChatID $chatID-FileURL $fileURL#------------------------------------------------------------------------------------------------# send a photo message from a URL sourceSend-TelegramURLPhoto-BotToken $botToken-ChatID $chatID-PhotoURL $photoURL#------------------------------------------------------------------------------------------------#send a sticker message from a URL sourceSend-TelegramURLSticker-BotToken $botToken-ChatID $chatID-StickerURL $stickerURL#------------------------------------------------------------------------------------------------# send a video message from a URL sourceSend-TelegramURLVideo-BotToken $botToken-ChatID $chatID-VideoURL $videoURL#------------------------------------------------------------------------------------------------# send information about a venueSend-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" }
#--------------------------------------------------------------------------

Notes

This PowerShell project was created with Catesta.

Contributing

If you'd like to contribute to pwshEmojiExplorer, please see the contribution guidelines.

License

This project is licensed under the MIT License.

About

Send messages via the Telegram Bot API using PowerShell

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

135 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages