iniital commit

It's a telegram bot
This commit is contained in:
David Todd (c0de) 2018-03-10 19:25:11 -06:00
commit 5ea487a42b
5 changed files with 106 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
venv/*
set_env.sh
*.pyc

30
example_msg Normal file
View File

@ -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
}

55
pushtest.py Normal file
View File

@ -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()

BIN
pushtest.pyc Normal file

Binary file not shown.

18
requirements.txt Normal file
View File

@ -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