commit 5ea487a42b4e7978fa9662b7b97700e42008bc78 Author: David Todd (c0de) Date: Sat Mar 10 19:25:11 2018 -0600 iniital commit It's a telegram bot diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a3b82eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv/* +set_env.sh +*.pyc diff --git a/example_msg b/example_msg new file mode 100644 index 0000000..42c408e --- /dev/null +++ b/example_msg @@ -0,0 +1,30 @@ +{ + 'message': { + 'delete_chat_photo': False, + 'new_chat_photo': [], + 'from': { + 'username': u'c0defox', + 'first_name': u'c0de', + 'is_bot': False, + 'id': 48143813, + 'language_code': u'en-US' + }, + 'text': u'mow', + 'caption_entities': [], + 'entities': [], + 'channel_chat_created': False, + 'new_chat_members': [], + 'supergroup_chat_created': False, + 'chat': { + 'username': u'c0defox', + 'first_name': u'c0de', + 'type': u'private', + 'id': 48143813 + }, + 'photo': [], + 'date': 1520738702, + 'group_chat_created': False, + 'message_id': 33 + }, + 'update_id': 127741687 +} \ No newline at end of file diff --git a/pushtest.py b/pushtest.py new file mode 100644 index 0000000..2935f27 --- /dev/null +++ b/pushtest.py @@ -0,0 +1,55 @@ +import os +import pusher +import logging +import uuid +from telegram.ext import Updater, CommandHandler, MessageHandler, Filters + +pusher_client = pusher.Pusher( + app_id=os.environ['pusher_appid'], + key=os.environ['pusher_key'], + secret=os.environ['pusher_secret'], + cluster='us2', + ssl=True +) + +updater = Updater(token=os.environ['telegram_token']) +dispatcher = updater.dispatcher + +logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + level=logging.DEBUG) + +ids = dict({}) + +def _save_id(id, chat_id): + ids[chat_id] = { + 'id': id, + 'chat_id': chat_id + } + return str(ids[chat_id]['id']) + +def generate_id(chat_id): + return _save_id(uuid.uuid4(), chat_id) + +def start(bot, update): + chat_id = update.message.chat_id + bot_msg = "Visit https://dev.c0defox.es/push/?channel=%s\ + and then come back to say something to me!" % generate_id(chat_id) + bot.send_message(chat_id=chat_id, text=bot_msg) + +start_handler = CommandHandler('start', start) +dispatcher.add_handler(start_handler) + +def echo(bot, update): + chat_id = update.message.chat_id + # Send the push notification to the session (uuid) + pusher_client.trigger(str(ids[chat_id]['id']), 'my-event', + {'message': update.message.text}) + bot.send_message(chat_id=chat_id, text="Notification Sent!") + +echo_handler = MessageHandler(Filters.text, echo) +dispatcher.add_handler(echo_handler) +# pusher_client.trigger('my-channel', 'my-event', {'message': 'I\'m a fox! :3'}) + +# Start being a TG bot +updater.start_polling() + diff --git a/pushtest.pyc b/pushtest.pyc new file mode 100644 index 0000000..7f39735 Binary files /dev/null and b/pushtest.pyc differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..036de80 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,18 @@ +asn1crypto==0.24.0 +certifi==2018.1.18 +cffi==1.11.5 +chardet==3.0.4 +cryptography==2.1.4 +enum34==1.1.6 +future==0.16.0 +idna==2.6 +ipaddress==1.0.19 +ndg-httpsclient==0.4.4 +pusher==1.7.4 +pyasn1==0.4.2 +pycparser==2.18 +pyOpenSSL==17.5.0 +python-telegram-bot==10.0.1 +requests==2.18.4 +six==1.11.0 +urllib3==1.22