tips:telegram

This is an old revision of the document!


Telegram

Create BOT with https://telegram.me/botfather

TOKEN=xyz

registrare un webhook (consigliato)

pip install python-telegram-bot

ipython
import telegram
TOKEN="xyz"
bot = telegram.Bot(TOKEN)
bot.setWebhook("https://giano.comune.verona.it/giano")

registrare un webhook (non funziona)

curl -i -H "Accept: application/json" -H "Content-Type: application/json" \
  -X POST --data-urlencode '{"url":"https://giano.comune.verona.it/giano"}' \
  https://api.telegram.org/bot${TOKEN}/setWebhook
curl -s -X POST https://api.telegram.org/bot${TOKEN}/sendMessage \
-d text="this is a message" \
-d chat_id=73496590 \
| jq .
curl -s -X POST https://api.telegram.org/bot${TOKEN}/getUpdates | jq .

certificato self signed

openssl req -newkey rsa:2048 -sha256 -nodes -keyout key.pem -x509 -days 365 -out cert.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Company/CN=example.com"

curl -F url="https://example.com:8443/<token>" -F certificate@=cert.pem 
  • With BotFather click /setjoingroups, choose BOT
  • Add to group @BOT
  • Send a message to group
  • Give .result.message.chat.id from curl https://api.telegram.org/bot${TOKEN}/getUpdates (negative number)

Send a message to group sendmessage_-d_chat_id_chatid_text_my_sample_text}

#!/bin/bash
 
echo "============================================="
echo "==     Telegram Script Installer v 0.1     =="
echo "==                                         =="
echo "==            by Jalcaldea                 =="
echo "============================================="
 
echo "Downloading necesary files..."
 
cd /tmp
wget -O - https://tdesktop.com/linux > tsetup.tar.gz
wget -O - https://raw.githubusercontent.com/telegramdesktop/tdesktop/master/Telegram/Telegram/Images.xcassets/Icon.iconset/icon_256x256@2x.png > icon.png
 
echo "Making destination folder..."
 
sudo mkdir /usr/share/telegram
sudo chmod +x /usr/share/telegram
 
echo "Extracting files..."
 
tar -xvJf tsetup.tar.gz
cd ./Telegram
 
echo "Copying new files..."
sudo cp ./Updater /usr/share/telegram/Updater
sudo cp ./Telegram /usr/share/telegram/Telegram
user=$(whoami)
sudo chown -R $user:$user /usr/share/telegram/.
 
echo "Making desktop files..."
 
cd /tmp
 
sudo echo "[Desktop Entry]" > telegram.desktop
sudo echo "Name=Telegram" >> telegram.desktop
sudo echo "GenericName=Chat" >> telegram.desktop
sudo echo "Comment=Chat with yours friends" >> telegram.desktop
sudo echo "Exec=/usr/share/telegram/Telegram" >> telegram.desktop
sudo echo "Terminal=false" >> telegram.desktop
sudo echo "Type=Application" >> telegram.desktop
sudo echo "Icon=/usr/share/telegram/icon.png" >> telegram.desktop
sudo echo "Categories=Network;Chat;" >> telegram.desktop
sudo echo "StartupNotify=false" >> telegram.desktop
 
sudo cp icon.png /usr/share/telegram/icon.png
sudo cp telegram.desktop /usr/share/applications/telegram.desktop
 
echo "Removing old files..."
 
rm /tmp/tsetup.tar.gz
rm /tmp/icon.png
rm /tmp/telegram.desktop
rm -R /tmp/Telegram
 
 
echo "Installation Complete! Launching Telegram..."
 
/usr/share/telegram/Updater &
  • tips/telegram.1478768603.txt.gz
  • Last modified: 2016/11/10 10:03
  • by scipio