From 5ea487a42b4e7978fa9662b7b97700e42008bc78 Mon Sep 17 00:00:00 2001 From: "David Todd (c0de)" Date: Sat, 10 Mar 2018 19:25:11 -0600 Subject: [PATCH] iniital commit It's a telegram bot --- .gitignore | 3 +++ example_msg | 30 ++++++++++++++++++++++++++ pushtest.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++ pushtest.pyc | Bin 0 -> 1917 bytes requirements.txt | 18 ++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 .gitignore create mode 100644 example_msg create mode 100644 pushtest.py create mode 100644 pushtest.pyc create mode 100644 requirements.txt 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 0000000000000000000000000000000000000000..7f39735a8894fa119bde73e0277aaa0ecd7aa4f5 GIT binary patch literal 1917 zcmah}OK&4Z5Uw7_uf%pXFK-+WOc0Tr!zKu=B7{~55ndN8G+{Xm2Wv9jvB#N*HQkOj zQaFWw!Igi=4}h;~>^KL+dfYu#)zv*!UwvJ*zq^}_KmQ72TK=~1{u;x6p@=m8ic+HR zNmdl9mEEJzTgf#FYa)A;ZctXIuufTn!Uknc3Y(O*C~T23ie_!nH8MoAP0|}Q(Djwl zfYMwkEhzAW&lZ_2dZc>TAyX%fx!T*M!6T`#OQuV+9)&$J9?iB%_ef)YA?ge4^px45 zgy<2$?~>l3KakNL>0J@_N$-hpK&C-@pUeS0BDFr59?f2o>GMXV55(z^3_@(tY(VBv z{Ek+BN0pzVt6?7qCja0!8g4*zO-yg+I&!9TJ;;|umPNV#5hGoielpfZ6SFe$j_;Ec z8?0+Uj^^`mqFo2#d|{`i9K!-b4Tf8D?>5&9tnwCX;?g+RU9T)He0H2JEJwrp7xr^` zTbsH%bXVM(T;g;lHIp*R#+8Xry(!8pa`rXElVN0Imt^MD`mg+xVIDn+skt-hGd-)a zJGJrwS&cm$!GlA%#IT=YN<4ZH)?GY+XC7TRB1mtl*8p@JTn%~0$njnvAlXbK2Y80y zEJ-SfwnJVIc6i#wG{mST%N%DAow4q0e(ze)$2Ph%IN~K_%LY<4)l@w%<}-Obg}Da> z;W$v)1G_k0@a0NAK9bmieRko>FBXW9F=gSkxV$eKj&5RdQ-UoB=p(3>Qz0dYaTt8y zC5FAg1V}1yW>r9n`o9Z^Gh9dru*w21-2=z#DNTr$qZ`@ZF#np^#Q9U_=Jw0;b8YU< z;?K0XDc+qKd(JqWpIHC-53Kdw)Z~6#WX8Xa;#=PpzK!mE3xk^``GgIbIhI@n2xs0o z`DVZfOVO5`sC<~%*5rD;vPYtQR$9Z;9SY;tAN3L zLXp`lD2^a7OlT{LfE}0x><~8a62<|>M6F!Vf@*Z}SR;kP&(JZ%4_!<**61=RM?yX! zQ+EFf7b17T0Cq_@ID}-Gn4`iaH%T11q{#g%I2{jp_uBRO4UW?U9s+_ZlgY%C0n<@V z3yvUF{QH1yAM*4b>N7GXo))KgFKORV`*?i4s>EjhsCcS%{~LX2O^g$X`pC(gPmaw+XhCw3mW7`@K%ow$x{ z5?>biO)`-i_3d}xy!}Cr&`Inn82H`^!KBgxoUmX#U3OYNDAIbR2TTtEPx4?SR!eJg ziS(aM<4soRMQXm{Z0#AQj;fwdyteAf(@^bNU$wn$wdr-dcC%e;*SA&IYd3b)zlgPP AlmGw# literal 0 HcmV?d00001 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