Linux send message to telegram

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

send messages via linux command line via Telegram Bot API

centminmod/telegram-send

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

readme.md

Send or update messages or send text files to your own Telegram Bot API created using BotFather:

Telegram BotFather Bot Creation

Requires jq json tool install:

Create and populate tgtoken.ini file in same directory as tgsend.sh with the following:

tgtoken='YOUR_TELEGRAM_BOT_API_TOKEN' tgchatid='YOUR_TELEGRAM_CHATID' tgapi="https://api.telegram.org/bot$tgtoken" 

You can find your Telegram chat id to populate variable tgchatid using the following command:

tgtoken='YOUR_TELEGRAM_BOT_API_TOKEN' tgapi="https://api.telegram.org/bot$tgtoken curl -4s "$tgapi/getUpdates" | jq -r '.result[].message.chat.id' 
./tgsend.sh Usage: ./tgsend.sh send "your message in double quotes" ./tgsend.sh sendhtml "your message in double quotes" disable notifications: ./tgsend.sh sendq "your message in double quotes" ./tgsend.sh sendhtmlq "your message in double quotes" update existing message with message_id: ./tgsend.sh update "your message in double quotes" message_id ./tgsend.sh updatehtml "your message in double quotes" message_id update existing message with message_id & disable notifications: ./tgsend.sh updateq "your message in double quotes" message_id ./tgsend.sh updatehtmlq "your message in double quotes" message_id send file ./tgsend.sh sendf filename 

Send messages in plain text or HTML format

./tgsend.sh send "message text"
./tgsend.sh sendhtml "message html"

Telegram Messages

Update an existing message with message_id

Читайте также:  Удалить linux через windows

./tgsend.sh updateq "updated message" 38

Telegram Messages

Telegram File Send

Send text message with Telegram message_id added

New feature which by default is enabled is to add the message_id to the messages via option tg_addmsgid=’y’

Telegram File Send

Sending Centmin Mod LEMP stack cminfo command for JSON formatted cpu and memory statistics

./tgsend.sh send "$(cminfo sar-json | jq -r '."cpu-load"[]')" < "from": "centmin", "to": "George", "date": "2021-07-08T01:16:15Z", "message": "[msgid: 40] " > 
./tgsend.sh send "$(cminfo sar-json | jq -r '."memory"')" < "from": "centmin", "to": "George", "date": "2021-07-08T01:17:09Z", "message": "[msgid: 41] " > 

Telegram File Send

Cloudflare Firewall Event log message sent

My custom cf-analytics-graphql.sh script querying Cloudflare Firewall GraphQL API for a sepcific IP address — 185.34.23.76 and filter only JS Challenge triggered events for past 24hrs of firewall event entries and saving JSON formatted output in file at /home /cf-graphql-json-output/cf-graphql-ip.json which we can send via Telegram Bot. Unfortunately, Telegram messages have a 4096 character limit, so larger messages are not supported in tgsend.sh yet — working on adding support to paginate longer messages to be send by multiple messages. But for purpose of this example, the JSON output is < 4096 characters.

./cf-analytics-graphql.sh ip-hrs 24 185.34.23.76 jschallenge JSON log saved: /home/cf-graphql-json-output/cf-graphql-ip.json CSV converted log saved: /home/cf-graphql-json-output/cf-graphql-ip.csv < "query": "query < viewer < zones(filter: ) < firewallEventsAdaptiveGroups( limit: $limit, filter: $filter, orderBy: [datetime_DESC] ) < dimensions < action botScore botScoreSrcName source datetime clientIP clientAsn clientCountryName edgeColoName clientRequestHTTPProtocol clientRequestHTTPHost clientRequestPath clientRequestQuery clientRequestScheme clientRequestHTTPMethodName clientRefererHost clientRefererPath clientRefererQuery clientRefererScheme edgeResponseStatus clientASNDescription userAgent kind originResponseStatus ruleId rayName >> > > >", "variables": < "zoneTag": "zoneid", "limit": 100, "filter": < "clientIP": "185.34.23.76", "action": "jschallenge", "datetime_geq": "2021-07-11T04:25:24Z", "datetime_leq": "2021-07-12T04:25:24Z" >> > ------------------------------------------------------------------ Cloudflare Firewall (enterprise) ------------------------------------------------------------------ since: 2021-07-11T04:25:24Z until: 2021-07-12T04:25:24Z ------------------------------------------------------------------ 1 Firewall Events for Request IP: 185.34.23.76 ------------------------------------------------------------------ 1 185.34.23.76 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME GET HTTP/1.0 892c40e1bef548368f6b37ab2a1dcf37 ------------------------------------------------------------------ 1 185.34.23.76 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME GET HTTP/1.0 ------------------------------------------------------------------ 1 185.34.23.76 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME domain.com GET HTTP/1.0 ------------------------------------------------------------------ 1 185.34.23.76 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME domain.com GET HTTP/1.0 / ------------------------------------------------------------------ 185.34.23.76 66d11159cf2f7b43 503 1xHeuristics jschallenge 47895 R-LINE-AS RU DME 2021-07-11T09:39:59Z domain.com GET HTTP/1.0 / ------------------------------------------------------------------ < "results": [ < "action": "jschallenge", "botScore": 1, "botScoreSrcName": "Heuristics", "clientASNDescription": "R-LINE-AS", "clientAsn": "47895", "clientCountryName": "RU", "clientIP": "185.34.23.76", "clientRefererHost": "domain.com", "clientRefererPath": "", "clientRefererQuery": "", "clientRefererScheme": "https", "clientRequestHTTPHost": "domain.com", "clientRequestHTTPMethodName": "GET", "clientRequestHTTPProtocol": "HTTP/1.0", "clientRequestPath": "/", "clientRequestQuery": "", "clientRequestScheme": "https", "datetime": "2021-07-11T09:39:59Z", "edgeColoName": "DME", "edgeResponseStatus": 503, "kind": "firewall", "originResponseStatus": 0, "rayName": "66d11159cf2f7b43", "ruleId": "892c40e1bef548368f6b37ab2a1dcf37", "source": "firewallrules", "userAgent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3355.4 Safari/537.36" >] > 
./tgsend.sh send "$(cat /home/cf-graphql-json-output/cf-graphql-ip.json | jq -r)" < "from": "centmin", "to": "George", "date": "2021-07-12T04:31:49Z", "message": "[msgid: 50] \n ]\n>" > 

Источник

Bash Script to Send a Message in Telegram from your Terminal!

Have you ever wanted to send a message from your terminal? Think about how convenient that would be as a developer who works in a terminal for 60% of the time. I know for me it was a game changer! There are api’s available for use with pulse sms and others but this tutorial is a quick right up on using Telegrams API.

Читайте также:  Удалить линукс через биос

What is Telegram?

Telegram is a cloud-based instant messaging and voice-over-IP service. It was developed by the Russian entrepreneur Pavel Durov and his brother Nikolai. Telegram is available for Android, iOS, Windows, macOS, and Linux, and it supports a wide range of languages. Telegram is known for its focus on security and privacy. It offers end-to-end encryption for all messages and calls, and it allows users to create private and secret chats that are not stored on the company’s servers. Telegram also offers a range of features that make it popular among users, such as the ability to send large files, create group chats with up to 200,000 members, and use bots to automate tasks. Telegram is a free and open-source platform, and it has a large and active community of users and developers. It has become one of the most popular messaging platforms in the world, with over 500 million monthly active users. You can download it in your respective app store!

Simple Bash Script to the Rescue

bin/bash/scripting doggy

To send a message in Telegram using a simple Bash script, you can use the curl command to make an HTTP POST request to the Telegram API. The API will allow you to send a message to a specified chat or user, and the message will be delivered instantly.

Here is a simple Bash script that you can use to send a message in Telegram:

# Set the API token and chat ID API_TOKEN="" CHAT_ID="" # Set the message text MESSAGE="This is a test message" # Use the curl command to send the message curl -s -X POST https://api.telegram.org/bot$API_TOKEN/sendMessage -d chat_id=$CHAT_ID -d text="$MESSAGE" 

How to use our Script:

To use this script, you will need to replace and with the API token and chat ID of your Telegram bot and the user or group you want to send the message to, respectively. You will also need to replace This is a test message with the text of the message you want to send. Once you have set these values, you can run the script by calling the bash command and passing the script file as an argument, like this:

bash send_telegram_message.sh 

paper plane flying and stuff like that my man.

What’s our Script Doing?

The script will then send the message to the specified user or group on Telegram. You can use this script as a starting point and modify it to suit your specific needs. For example, you could add command-line arguments to the script to make it more flexible and allow you to specify the API token, chat ID, and message text when you run the script. You can find more detailed instructions and information about the Telegram API in the Telegram API documentation. Please feel free to reach out to me with any questions or if you just want to chat! NathanNOSudo

Читайте также:  Графический редактор alt linux

Источник

Sending Telegram Messages with Linux Scripts

If you’re a Linux user, you may be familiar with bash shell scripts. These scripts are a powerful tool for automating tasks and processes. In this article, we’ll show you how to use bash shell scripts to send messages or notifications to Telegram on Linux.

Step 1: Create a Telegram Bot

The first step is to create a Telegram bot by following these steps:

  1. Open Telegram and search for the BotFather account.
  2. Start a chat with BotFather and type /newbot to create a new bot.
  3. Follow the prompts and enter a name and username for your bot.
  4. BotFather will provide you with a unique API token for your bot. Save this token, as you’ll need it later to send messages to your bot.

Step 2: Install the Required Libraries

To interact with the Telegram API, we’ll need to install the “curl” library on our Linux system. You can do this by running the following command:

Step 3: Create the Bash Shell Script

Now it’s time to create the bash shell script that will send messages or notifications to your Telegram bot. Open a text editor and create a new file called “send_telegram.sh”. Then copy and paste the following code into the file:

#!/bin/bash TOKEN="your_bot_token" CHAT_ID="your_chat_id" MESSAGE="Hello, world!" curl -s -X POST https://api.telegram.org/bot$TOKEN/sendMessage -d chat_id=$CHAT_ID -d text="$MESSAGE" > /dev/null

Replace “your_bot_token” with the API token provided by BotFather, and “your_chat_id” with the ID of the chat where you want to receive the message. You can find your chat ID by sending a message to your bot and then using the following command in your web browser:

https://api.telegram.org/bot/getUpdates

Look for the “chat” object in the response and copy the “id” value. Finally, customize the message variable to include the message you want to send.

Step 4: Test the Script

Save the file and make it executable by running the following command:

chmod +x send_telegram.sh Then run the script by typing the following command:

./send_telegram.sh If everything is set up correctly, you should receive a message from your bot in your Telegram app.

Step 5: Automate Notifications

Now that you have a working script, you can automate notifications by running the script as a cron job or using other automation tools like Ansible. Simply set up the script to run at specific intervals or trigger it when certain events occur.

Conclusion

Using bash shell scripts to send messages or notifications to Telegram on Linux can save you time and effort. By following these simple steps, you can set up your own notification system to stay informed and up-to-date with the latest information. From setting up a Telegram bot to testing and automating notifications, this guide covers everything you need to get started with sending Telegram messages using bash shell scripts in Linux.

Источник

Оцените статью
Adblock
detector