• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created over 6 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Send messages via the Telegram Bot API using PowerShell

PoshGram

Minimum Supported PowerShell Version PowerShell Gallery Cross Platform License

Branch Windows MacOS Linux
main Build Status AppVeyor Build status Build Status
Enhancements Build Status AppVeyor Build status Build Status

Synopsis

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

PoshGram Gif Demo

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.

PoshGram provides the following functions:

Why

The Telegram Bot API requires very specific formatting and criteria for Bot messaging. The goal of this project is to abstract that complexity away in favor of simple and direct PowerShell commands.

PoshGram also opens up several programmatic use cases:

  • Load PoshGram into Azure functions to alert you of potential conditions
  • Load PoshGram into AWS Lambda to alert you of potential conditions
  • Custom scripts tied to task scheduler could alert you to potential system conditions
    • Test-LowDisk.ps1 tied to task scheduler --> leverages PoshGram to alert you if low disk condition found
  • Enable a script to provide Telegram notifications
  • In a ForEach you could easily message multiple chat groups that your bot is a member of

Installation

Prerequisites

Installing PoshGram via PowerShell Gallery

#from a 6.1.0+ PowerShell session
Install-Module -Name "PoshGram" -Scope CurrentUser

Quick start

#------------------------------------------------------------------------------------------------
#import the PoshGram module
Import-Module -Name "PoshGram"
#------------------------------------------------------------------------------------------------
#easy way to validate your Bot token is functional
Test-BotToken -BotToken $botToken
#------------------------------------------------------------------------------------------------
#send a basic Text Message
Send-TelegramTextMessage -BotToken $botToken -ChatID $chat -Message "Hello"
#------------------------------------------------------------------------------------------------
#send a photo message from a local source
Send-TelegramLocalPhoto -BotToken $botToken -ChatID $chat -PhotoPath $photo
#------------------------------------------------------------------------------------------------
#send a photo message from a URL source
Send-TelegramURLPhoto -BotToken $botToken -ChatID $chat -PhotoURL $photoURL
#------------------------------------------------------------------------------------------------
#send a file message from a local source
Send-TelegramLocalDocument -BotToken $botToken -ChatID $chat -File $file
#------------------------------------------------------------------------------------------------
#send a file message from a URL source
Send-TelegramURLDocument -BotToken $botToken -ChatID $chat -FileURL $fileURL
#------------------------------------------------------------------------------------------------
#send a video message from a local source
Send-TelegramLocalVideo -BotToken $botToken -ChatID $chat -Video $video
#------------------------------------------------------------------------------------------------
#send a video message from a URL source
Send-TelegramURLVideo -BotToken $botToken -ChatID $chat -VideoURL $videoURL
#------------------------------------------------------------------------------------------------
#send an audio message from a local source
Send-TelegramLocalAudio -BotToken $botToken -ChatID $chat -Audio $audio
#------------------------------------------------------------------------------------------------
#send an audio message from a URL source
Send-TelegramURLAudio -BotToken $botToken -ChatID $chat -AudioURL $audioURL
#------------------------------------------------------------------------------------------------
#send a map point location using Latitude and Longitude
Send-TelegramLocation -BotToken $botToken -ChatID $chat -Latitude $latitude -Longitude $longitude
#------------------------------------------------------------------------------------------------
#send an animated gif from a local source
Send-TelegramLocalAnimation -BotToken $botToken -ChatID $chat -AnimationPath $animation
#------------------------------------------------------------------------------------------------
#send an animated gif from a URL source
Send-TelegramURLAnimation -BotToken $botToken -ChatID $chat -AnimationURL $AnimationURL
#------------------------------------------------------------------------------------------------
#sends a group of photos or videos as an album from a local source
Send-TelegramMediaGroup -BotToken $botToken -ChatID $chat -FilePaths (Get-ChildItem C:\PhotoGroup | Select-Object -ExpandProperty FullName)
#------------------------------------------------------------------------------------------------
#send a contact's information
Send-TelegramContact -BotToken $botToken -ChatID $chat -PhoneNumber $phone -FirstName $firstName
#------------------------------------------------------------------------------------------------
#send information about a venue
Send-TelegramVenue -BotToken $botToken -ChatID $chat -Latitude $latitude -Longitude $longitude -Title $title -Address $address
#------------------------------------------------------------------------------------------------
#send a poll with a question and options
Send-TelegramPoll -BotToken $botToken -ChatID $chat -Question $question -Options $opt
#------------------------------------------------------------------------------------------------
#get information for a Telegram sticker pack
Get-TelegramStickerPackInfo -BotToken $botToken -StickerSetName STPicard
#------------------------------------------------------------------------------------------------
#sends Telegram sticker message from a local source
Send-TelegramLocalSticker -BotToken $botToken -ChatID $chat -StickerPath $sticker
#------------------------------------------------------------------------------------------------
#send Telegram sticker with known sticker file_id
Send-TelegramSticker -BotToken $botToken -ChatID $chat -FileID $sticker
#send Telegram sticker (best effort) with sticker pack name and emoji shortcode
Send-TelegramSticker -BotToken $botToken -ChatID $chat -StickerSetName STPicard -Shortcode ':slightly_smiling_face:'
#------------------------------------------------------------------------------------------------
#send a sticker message from a URL source
Send-TelegramURLSticker -BotToken $botToken -ChatID $chat -StickerURL $StickerURL
#------------------------------------------------------------------------------------------------
#send an animated emoji that will display a random value
Send-TelegramDice -BotToken $botToken -ChatID $chat -Emoji $emoji
#------------------------------------------------------------------------------------------------
###########################################################################
#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;$token = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx';$chat = '-nnnnnnnnn';Send-TelegramTextMessage -BotToken $token -ChatID $chat -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
$token = #########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx
$chat = -#########
$test = "I am a test"
& '.\Program Files\PowerShell\6\pwsh.exe' -command "& {Import-Module PoshGram;Send-TelegramTextMessage -BotToken $token -ChatID $chat -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-preview\pwsh.exe' -command { Import-Module PoshGram;$token = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx';$chat = '-nnnnnnnnn';Send-TelegramTextMessage -BotToken $token -ChatID $chat -Message "Test from 5.1 calling 7+ to send Telegram Message via PoshGram" }
#--------------------------------------------------------------------------

FAQ

PoshGram - FAQ

Author

Jake Morrison - https://www.techthoughts.info/

Contributors

Notes

For a description of the Bot API, see this page: https://core.telegram.org/bots/api

This PowerShell project was created with Catesta.

License

This project is licensed under the MIT License.

Changelog

Reference the Changelog

More Repositories

1

Catesta

Catesta is a PowerShell module and vault project generator. It uses templates to rapidly scaffold test and build integration for a variety of CI/CD platforms.
PowerShell
165
star
2

Learn-PowerShell-Code-Examples

Contains code examples used in the Learn PowerShell Video & Blog series
PowerShell
154
star
3

PSGalleryExplorer

Search, explore, and discover PowerShell Gallery modules.
PowerShell
33
star
4

Diag-V

Hyper-V PowerShell Diagnostic Utility
PowerShell
22
star
5

pwshPlaces

pwshPlaces is a PowerShell module that can help you discover places and search for points of interest around the globe.
PowerShell
14
star
6

pwshCloudCommands

Search, discover, and identify PowerShell cloud commands across multiple cloud providers.
PowerShell
11
star
7

iLORestAPI

Basic PowerShell examples for interacting with HP iLO via the RestAPI
PowerShell
10
star
8

ApertaCookie

ApertaCookie is a PowerShell module that can extract and decrypt cookie data from the SQLite databases of several popular browsers.
PowerShell
10
star
9

PoshNotify

PowerShell application powered by Azure Functions that sends PowerShell news to Slack
PowerShell
9
star
10

PSSummit-One-MOF

Contains code demoed at the 2018 PowerShell Summit for One MOF to rule them all, and in the Azure bind them
PowerShell
7
star
11

pwshEmojiExplorer

PowerShell module that enables you to search, discover, and retrieve emoji Unicode info directly through the command line.
PowerShell
6
star
12

pwshBedrock

pwshBedrock is a PowerShell module designed to simplify interaction with Amazon Bedrock foundation models. It enables users to send messages, retrieve responses, manage conversation contexts, generate images, and estimate costs. Supporting both InvokeModel and Converse API, it streamlines AI integration in PowerShell workflows.
PowerShell
5
star
13

NanoServer

PowerShell
3
star
14

techthoughts2

3
star
15

QuickVMLab

Powershell tool capable of rapidly building Hyper-V VMs from specified source VHDX
PowerShell
2
star
16

DeleteDscTmpFile

Custom DSC module for resolving clear text MOFs created by Azure Automation DSC
PowerShell
2
star
17

AzurePS-V

PowerShell module that verifies a local system meets all prerequisites and is capable of running AzureRM PowerShell.
PowerShell
2
star
18

fermiparadox

CI/CD repository for the Fermi Paradox Theory Project
HTML
2
star
19

ADPinger

Visual Basic
1
star