Отправка сообщений в telegram

У меня есть телеграм бот на c#, через которого мне нужно отправить файл больше 50мб. Почитав вопросы про это понял, что нужно разворачивать локальный сервер для бота. Начал заниматься этим, прописал необходимые команды в PowerShell, заранее получил api-id и api-hash. Установка сервера вроде завершена, но как продолжить работу дальше – не знаю.
Команды, который я прописывал

git clone --recursive https://github.com/tdlib/telegram-bot-api.git
cd telegram-bot-api
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
./vcpkg.exe install gperf:x64-windows openssl:x64-windows zlib:x64-windows
cd ..
Remove-Item build -Force -Recurse -ErrorAction SilentlyContinue
mkdir build
cd build
cmake -A x64 -DCMAKE_INSTALL_PREFIX:PATH=.. -DCMAKE_TOOLCHAIN_FILE:FILEPATH=../vcpkg/scripts/buildsystems/vcpkg.cmake ..
cmake --build . --target install --config Release
cd ../..
dir telegram-bot-api/bin/telegram-bot-api*

Еще бы хотелось узнать, как переподключить бота на свой локальный сервер, был бы признателен!

kepeeennnddd's user avatar

Здесь говорится, что он вам нужен только если у вас ограничения на скачивание и требуется качать файлы больше 2 Гб, ну и прочие увеличения лимитов.

Вы скачали локальный сервер и скомпилировали его. Дальше вам требуется, настроить автозапуск его и создать HTTPS Proxy:

После чего вас ждёт след. раздел

DerSkythe's user avatar

Create New Telegram bot with BotFather

Your user ID: 987654321

And here’s a command to send a message to Telegram:

$message="Test message alert from PowerShell"
$Response = Invoke-RestMethod -Uri "https://api.telegram.org/bot$($tg_token)/sendMessage?chat_id=$($tg_chat_id)&text=$($Message)"

Once you run that one, you should get a message from the bot.

You can use emoji and HTML text formatting to make notifications more visually appealing and readable:

$message= $currend_data + "⚠️ Update Script <b>SAP_DB_Update</b> completed with errors"
$Response = Invoke-RestMethod -Uri "https://api.telegram.org/bot$($tg_token)/sendMessage?chat_id=$($tg_chat_id)&text=$($Message)&parse_mode=html"

PowerShell: sending messages to Telegram via bot

To work with PowerShell scripts, I recommend using the VS Code editor.

PowerShell script to send message via Telegram API

If you are accessing the Internet through a proxy server, you can use the -Proxy parameter of the Invoke-WebRequest cmdlet to specify the proxy settings. Use the -ProxyCredential argument to authenticate to a proxy.

:/>  Как создать батник для запуска команды в cmd — Общение — Корзина —

$Response = Invoke-RestMethod -Uri "https://api.telegram.org/bot$($Telegramtoken)/sendMessage?chat_id=$($Telegramchatid)&text=$($Message)" –Proxy "http://192.168.13.155:3128"

You can create a function from a script that sends a message to Telegram and add it to the PowerShell profile file in Windows:

function Send-Telegram {
        [CmdletBinding()]
        param(
            [Parameter()]
            [string] $Message
        )    
        $tg_token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        $tg_chat_id="987654321"
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        $Response = Invoke-RestMethod -Uri "https://api.telegram.org/bot$($tg_token)/sendMessage?chat_id=$($tg_chat_id)&text=$($Message)&parse_mode=html" 
        return $Response    
 }

Open a text file with a PowerShell profile that is automatically applied when powershell.exe/pwsh.exe starts:

PowerShell function to send a Telegram message

It is now possible to send a message to a Telegram channel from any PowerShell script.

Send-Telegram "My test message"

Оставьте комментарий