├── .gitignore ├── LICENSE ├── Procfile ├── README.md ├── app.json ├── bot.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | 91 | config.py -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Archit Verma 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: python bot.py --noreload -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YodaBot (Beta) 2 | 3 | Master Yoda, I am. Left Degobah I have, and come to messenger as a bot. 4 | 5 | [Message me](http://m.me/1621772074813073). Reply in my own style, I would. 6 | 7 | ## Demo 8 | 9 | ![GIF](http://i.giphy.com/VJpUrMyklIgIE.gif) 10 | 11 | ![](http://i.imgur.com/gn1Qa51.png?1) 12 | 13 | ### **[Watch Video](https://vimeo.com/163974400)** 14 | 15 | ## Live 16 | 17 | http://m.me/1621772074813073 18 | 19 | ## Deploy 20 | 21 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 22 | 23 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "YodaBot", 3 | "description": "A messenger bot for Master Yoda", 4 | "repository": "https://github.com/architv/yodabot", 5 | "keywords": ["python", "facebook", "chatbot"] 6 | } -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | import os 2 | from flask import Flask 3 | from flask import request 4 | import json 5 | import requests 6 | import urllib2, urllib 7 | 8 | import config 9 | 10 | app = Flask(__name__) 11 | 12 | def send_message(sender_id, text): 13 | try: 14 | str = urllib.quote(text) 15 | opener = urllib2.build_opener() 16 | opener.addheaders = [("X-Mashape-Authorization", config.MASHAPE_AUTHORIZATION)] 17 | socket = opener.open('https://yoda.p.mashape.com/yoda?sentence=' + 18 | str) 19 | content = socket.read() 20 | text = "Yoda says: " + content 21 | json_data = { 22 | "recipient": {"id": sender_id}, 23 | "message": {"text": text} 24 | } 25 | params = { 26 | "access_token": config.FB_MESSENGER_TOKEN 27 | } 28 | r = requests.post('https://graph.facebook.com/v2.6/me/messages', json=json_data, params=params) 29 | print(r, r.status_code, r.text) 30 | except: 31 | pass 32 | 33 | 34 | @app.route("/", methods=['POST', 'GET']) 35 | def main(): 36 | if request.method == 'GET': 37 | verification_code = 'bot_this_is_of_yoda' 38 | verify_token = request.args.get("hub.verify_token") 39 | if verification_code == verify_token: 40 | return request.args.get("hub.challenge") 41 | else: 42 | return 'hello world' 43 | 44 | elif request.method == 'POST': 45 | print 'hello' 46 | body = request.data 47 | print "BODY" + body 48 | messaging_events = json.loads(body)['entry'][0]['messaging'] 49 | for event in messaging_events: 50 | sender = event['sender']['id'] 51 | if event.get('message') and event['message'].get('text'): 52 | text = event['message']['text'] 53 | # sender = messaging_events[0]['sender']['id'] 54 | # text = messaging_events[0]['message']['text'] 55 | send_message(sender, text) 56 | return 'received' 57 | else: 58 | return 'Error' 59 | 60 | 61 | if __name__ == "__main__": 62 | # The default port of 5000 that a Flask app starts on does not work 63 | # for a Heroku deployment. Instead, you need to get the PORT environment 64 | # variable (that is set in each Heroku deployment environment, or dyno) 65 | # and start the app listening on that port 66 | # Read http://virantha.com/2013/11/14/starting-a-simple-flask-app-with-heroku/ 67 | app.debug = True 68 | port = int(os.environ.get("PORT", 8000)) 69 | app.run(host='0.0.0.0', port=port) 70 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==0.10.1 2 | Jinja2==2.8 3 | MarkupSafe==0.23 4 | Werkzeug==0.11.8 5 | argparse==1.2.1 6 | itsdangerous==0.24 7 | requests==2.9.1 8 | wsgiref==0.1.2 9 | --------------------------------------------------------------------------------