Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tips:telegram [2015/10/02 09:56] – [BOT] scipio | tips:telegram [2022/04/12 08:07] (current) – sscipioni | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Telegram ====== | ====== Telegram ====== | ||
- | ===== Installer ===== | + | {{tag> |
- | <code bash> | + | ===== channel |
- | # | + | |
- | + | ||
- | echo "=============================================" | + | |
- | echo " | + | |
- | echo " | + | |
- | echo " | + | |
- | echo " | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | cd /tmp | + | |
- | wget -O - https:// | + | |
- | wget -O - https:// | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | sudo mkdir / | + | |
- | sudo chmod +x / | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | tar -xvJf tsetup.tar.gz | + | |
- | cd ./ | + | |
- | + | ||
- | echo " | + | |
- | sudo cp ./Updater / | + | |
- | sudo cp ./Telegram / | + | |
- | user=$(whoami) | + | |
- | sudo chown -R $user:$user / | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | cd /tmp | + | |
- | + | ||
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | sudo echo " | + | |
- | + | ||
- | sudo cp icon.png / | + | |
- | sudo cp telegram.desktop / | + | |
- | + | ||
- | echo " | + | |
- | + | ||
- | rm / | + | |
- | rm / | + | |
- | rm / | + | |
- | rm -R / | + | |
- | + | ||
- | + | ||
- | echo " | + | |
- | + | ||
- | / | + | |
+ | send message to channel from bot (BOT_API_KEY required): | ||
+ | - add bot to channel as admin | ||
+ | - send message | ||
+ | |||
+ | < | ||
+ | curl https:// | ||
</ | </ | ||
+ | |||
===== BOT ===== | ===== BOT ===== | ||
+ | Create BOT with https:// | ||
< | < | ||
- | TOKEN=113260947: | + | TOKEN=xyz |
</ | </ | ||
- | registrare un webhook | + | registrare un webhook |
+ | < | ||
+ | pip install python-telegram-bot ipython | ||
+ | |||
+ | ipython | ||
+ | import telegram | ||
+ | TOKEN=" | ||
+ | bot = telegram.Bot(TOKEN) | ||
+ | bot.setWebhook(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | registrare un webhook (non funziona) | ||
< | < | ||
curl -i -H " | curl -i -H " | ||
Line 89: | Line 50: | ||
curl -s -X POST https:// | curl -s -X POST https:// | ||
</ | </ | ||
+ | |||
+ | |||
+ | certificato self signed | ||
+ | < | ||
+ | openssl req -newkey rsa:2048 -sha256 -nodes -keyout key.pem -x509 -days 365 -out cert.pem -subj "/ | ||
+ | |||
+ | curl -F url=" | ||
+ | </ | ||
+ | |||
+ | ==== Add BOT to group ==== | ||
+ | |||
+ | * With BotFather click / | ||
+ | * Add @BOT to group | ||
+ | * Send a message to group | ||
+ | * Give .result.message.chat.id from curl https:// | ||
+ | <code bash> | ||
+ | TOKEN= | ||
+ | curl https:// | ||
+ | </ | ||
+ | |||
+ | |||
+ | Send a message to group | ||
+ | <code bash> | ||
+ | TOKEN= | ||
+ | CHATID= | ||
+ | curl -X POST " | ||
+ | </ | ||
+ | |||
+ | To enable BOT to receive messages from group disable "group privacy" | ||
+ | |||
+ | ==== curl ==== | ||
+ | |||
+ | send message | ||
+ | <code bash> | ||
+ | #/bin/sh | ||
+ | |||
+ | API=" | ||
+ | CHATID=123456 | ||
+ | TEXT=" | ||
+ | |||
+ | curl --data chat_id=$CHATID --data-urlencode " | ||
+ | </ | ||
+ | ===== bot video ===== | ||
+ | |||
+ | <code python> | ||
+ | # | ||
+ | # -*- coding: utf-8 -*- | ||
+ | """ | ||
+ | |||
+ | # This program is dedicated to the public domain under the CC0 license. | ||
+ | """ | ||
+ | |||
+ | TOKEN=" | ||
+ | AUTHORIZED=[73496590, | ||
+ | |||
+ | import logging | ||
+ | from telegram import InlineKeyboardButton, | ||
+ | from telegram.ext import Updater, CommandHandler, | ||
+ | import subprocess | ||
+ | |||
+ | logging.basicConfig(format=' | ||
+ | level=logging.INFO) | ||
+ | logger = logging.getLogger(__name__) | ||
+ | |||
+ | |||
+ | def _isAuthorized(update): | ||
+ | isOk = update.effective_user[' | ||
+ | if not isOk: | ||
+ | update.message.reply_text(' | ||
+ | return isOk | ||
+ | | ||
+ | | ||
+ | def reply(update, | ||
+ | reply_keyboard = [['/ | ||
+ | update.message.reply_text(message, | ||
+ | | ||
+ | |||
+ | def start(bot, update): | ||
+ | if _isAuthorized(update): | ||
+ | reply(update, | ||
+ | # | ||
+ | |||
+ | def show(bot, update): | ||
+ | print(" | ||
+ | if _isAuthorized(update): | ||
+ | user_id = update.effective_user[' | ||
+ | subprocess.call(["/ | ||
+ | reply(update, | ||
+ | |||
+ | def motion(bot, update): | ||
+ | print(" | ||
+ | if _isAuthorized(update): | ||
+ | user_id = update.effective_user[' | ||
+ | reply(update, | ||
+ | subprocess.call(["/ | ||
+ | |||
+ | def error(bot, update, error): | ||
+ | """ | ||
+ | logger.warning(' | ||
+ | |||
+ | |||
+ | def previewday(bot, | ||
+ | if _isAuthorized(update): | ||
+ | user_id = update.effective_user[' | ||
+ | message = update.message[' | ||
+ | camera = message[0] | ||
+ | try: | ||
+ | speed = int(message[1]) | ||
+ | except: | ||
+ | speed = 50 | ||
+ | reply(update, | ||
+ | makedayvideo(user_id, | ||
+ | |||
+ | |||
+ | def makedayvideo(user_id, | ||
+ | print(["/ | ||
+ | subprocess.call(["/ | ||
+ | |||
+ | def button(bot, update): | ||
+ | query = update.callback_query | ||
+ | chat_id=query.message.chat_id | ||
+ | |||
+ | bot.edit_message_text(text=' | ||
+ | makedayvideo(chat_id, | ||
+ | |||
+ | |||
+ | def buttonpreview(bot, | ||
+ | if _isAuthorized(update): | ||
+ | keyboard = [[InlineKeyboardButton(" | ||
+ | InlineKeyboardButton(" | ||
+ | InlineKeyboardButton(" | ||
+ | InlineKeyboardButton(" | ||
+ | InlineKeyboardButton(" | ||
+ | ]] | ||
+ | reply_markup = InlineKeyboardMarkup(keyboard) | ||
+ | update.message.reply_text(' | ||
+ | |||
+ | def main(): | ||
+ | updater = Updater(TOKEN) | ||
+ | |||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CommandHandler(' | ||
+ | updater.dispatcher.add_handler(CallbackQueryHandler(button)) | ||
+ | updater.dispatcher.add_error_handler(error) | ||
+ | |||
+ | updater.start_polling() | ||
+ | updater.idle() | ||
+ | |||
+ | |||
+ | if __name__ == ' | ||
+ | main() | ||
+ | </ | ||
+ | |||
+ | |||
+ |