This article shows you how to send a voice note file (e.g. an OPUS file) to a registered Telegram group from a bash shell script.
To send a Telegram message containing a voice note file to a group from a bash shell script, do this:
- First, learn how to send a simple text message to a group on the official site.
- With the above knowledge, you can now download our sample code.
- Locate the file
bash/group-send-telegram-opus.sh
.This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters#!/bin/bash ####################################################################### # You will need to have the utility `base64` available on your Linux # system to run this script. # # To install it: # sudo apt-get install coreutils ####################################################################### # TODO: Put down your own Client ID and secret here: INSTANCE_ID="YOUR_OWN_INSTANCE_ID_HERE" CLIENT_ID="YOUR_OWN_CLIENT_ID_HERE" CLIENT_SECRET="YOUR_OWN_SECRET_HERE" # TODO: Customize the following 5 files: group_name="Muscle Men Club" group_admin="12025550108" base64_audio=`base64 -w 0 ../assets/martin-luther-king.opus` fn="anyname.opus" caption="I have a dream" cat > /tmp/jsonbody.txt << _EOM_ { "group_name": "$group_name", "group_admin": "$group_admin", "voice_note": "$base64_audio", "filename": "$fn", "caption": "$caption" } _EOM_ curl --show-error -X POST \ -H "X-WM-CLIENT-ID: $CLIENT_ID" \ -H "X-WM-CLIENT-SECRET: $CLIENT_SECRET" \ -H "Content-Type: application/json" \ --data-binary @/tmp/jsonbody.txt \ https://api.whatsmate.net/v3/telegram/group/voice_note/message/$INSTANCE_ID echo -e "\n=== END OF DEMO ===" - Study the script and customize the TODO/FIXME lines.
- Change to the directory containing the script:
cd bash
- Run the script to send your group the first OPUS file:
./group-send-telegram-opus.sh
Happy coding :)