Saturday, 8 August 2020

powershell 12 telegram

telegram desktop download

https://desktop.telegram.org/

telegram web

https://telegram.org/dl/webogram

google app

telegram

How to Create a Telegram Bot and Send Message via bot API

https://www.youtube.com/watch?v=UhZtrhV7t3U

download telegram desktop -> add botfather to contact -> create new -> get bot name and token  

create new group -> add bot by searching bot name
open telegram web -> last few digits in the url are the chat id

https://api.telegram.org/bottoken/sendMessage?chat_id=chat id&text=Hello+World
open web browser -> replace token and chat id -> copy paste url
telegram received by bot on desktop

 #install powershell 7

https://www.howtogeek.com/663684/how-to-install-powershell-7-on-windows-10/

install-module poshgram

get-command -module poshgram

get-help Send-TelegramTextMessage -example

PS C:\Users\bob> get-module -name poshgram -listavailable

    Directory: C:\Users\bob\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands

---------- -------    ---------- ----                                --------- ----------------

Script     1.12.0                PoshGram                            Desk      {Get-TelegramStickerPackInfo, Send-Tele…

PS C:\Users\bob> get-volume

DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining      Size

----------- ------------ -------------- --------- ------------ ----------------- -------------      ----

C                        NTFS           Fixed     Healthy      OK                    679.58 GB 930.16 GB

                         NTFS           Fixed     Healthy      OK                    392.21 MB    823 MB

                         Unknown        Fixed     Healthy      Unknown                     0 B       0 B

PS C:\Users\bob> $volume = get-volume -errorAction stop | where-object {$_.DriveLetter -eq 'c'}

PS C:\Users\bob> $sizeRemaining = [math]::round($volume.SizeRemaining/1024/1024/1024,2)

PS C:\Users\bob> $percentFree = [int](($sizeRemaining/$volume.Size)*100)

PS C:\Users\bob> $botToken = "xxx"

PS C:\Users\bob> $chat = "-493233924"

PS C:\Users\bob> Send-TelegramTextMessage -BotToken $botToken -ChatID $chat -Message "$sizeRemaining GB ($percentFree%) free on C:\"

  ok result

  -- ------

True @{message_id=7; from=; chat=; date=1596923063; text=682.29 GB (73%) free on C:\}

                                            telegram message received by bot on smart phone

PS C:\Users\bob> Send-TelegramLocalPhoto -BotToken $botToken -ChatID $chat -PhotoPath 'C:\Users\bob\Downloads\tropical_beach_resorts-wallpaper-1920x1080.jpg'

  ok result
  -- ------
True @{message_id=8; from=; chat=; date=1596924540; photo=System.Object[]}

PS C:\Users\bob> Send-TelegramLocalDocument -BotToken $botToken -ChatID $chat -File 'C:\Users\bob\Desktop\redux.txt'

  ok result
  -- ------
True @{message_id=9; from=; chat=; date=1596925092; document=}
telegram picture and files received

reference:

https://www.youtube.com/watch?v=IABNJEl2ZWk&t=1535s

telegram bot

https://telegram.org/apps

https://core.telegram.org/bots

poshgram command

https://github.com/techthoughts2/PoshGram


No comments:

Post a Comment