├── src ├── __init__.py ├── conf │ ├── __init__.py │ ├── .env-example │ └── settings.py ├── tests │ └── __init__.py └── core.py ├── requirements.txt ├── LICENSE ├── README.md └── .gitignore /src/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/conf/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/conf/.env-example: -------------------------------------------------------------------------------- 1 | TELEGRAM_TOKEN= 2 | BASE_API_URL= -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | python-dotenv==0.15.0 2 | python-telegram-bot==10.1.0 -------------------------------------------------------------------------------- /src/conf/settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from dotenv import load_dotenv 4 | 5 | load_dotenv() 6 | 7 | TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN") 8 | BASE_API_URL = os.getenv("BASE_API_URL") 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Mauro de Carvalho 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 | -------------------------------------------------------------------------------- /src/core.py: -------------------------------------------------------------------------------- 1 | from telegram.ext import CommandHandler, Filters, MessageHandler, Updater 2 | 3 | from conf.settings import BASE_API_URL, TELEGRAM_TOKEN 4 | 5 | 6 | def start(update, context): 7 | response_message = "=^._.^=" 8 | context.bot.send_message( 9 | chat_id=update.effective_chat.id, text=response_message 10 | ) 11 | 12 | 13 | def http_cats(update, context): 14 | context.bot.sendPhoto( 15 | chat_id=update.effective_chat.id, photo=BASE_API_URL + context.args[0] 16 | ) 17 | 18 | 19 | def unknown(update, context): 20 | response_message = "Meow? =^._.^=" 21 | context.bot.send_message( 22 | chat_id=update.effective_chat.id, text=response_message 23 | ) 24 | 25 | 26 | def main(): 27 | # Create the Updater and pass it your bot's token. 28 | updater = Updater(token=TELEGRAM_TOKEN) 29 | 30 | # Get the dispatcher to register handlers 31 | dispatcher = updater.dispatcher 32 | 33 | # on different commands - answer in Telegram 34 | dispatcher.add_handler(CommandHandler("start", start)) 35 | dispatcher.add_handler(CommandHandler("http", http_cats)) 36 | dispatcher.add_handler(MessageHandler(Filters.command, unknown)) 37 | 38 | # Start the Bot 39 | updater.start_polling() 40 | 41 | # Block until the user presses Ctrl-C or the process receives SIGINT, 42 | # SIGTERM or SIGABRT. This should be used most of the time, since 43 | # start_polling() is non-blocking and will stop the bot gracefully. 44 | updater.idle() 45 | 46 | 47 | if __name__ == "__main__": 48 | print("press CTRL + C to cancel.") 49 | main() 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HTTP Cats Telegram Bot 2 | 3 | [![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/mdcg/http-cats-telegram-bot/blob/master/LICENSE) 4 | 5 | *A simple chatbot for the telegram that uses the HTTP Cats API* 6 | 7 | This project was created with the intention of helping the developers to create their first chatbots in the Telegram. 8 | You can find the tutorial for the creation of this chatbot by visiting the following link: [https://medium.com/@mdcg.dev/desenvolvendo-o-seu-primeiro-chatbot-no-telegram-com-python-a9ad787bdf6](https://medium.com/@mdcg.dev/desenvolvendo-o-seu-primeiro-chatbot-no-telegram-com-python-a9ad787bdf6) 9 | 10 | ### HTTP Cats 11 | 12 | Initially I would like to talk about this amazing API which was the main purpose of our chatbot, which is the [HTTP Cats](https://http.cat/)!! 13 | 14 | Basically, this API returns an image in the JPEG format with the "feline representation" of the HTTP status code. That's why I love the internet. 15 | 16 | ### python-telegram-bot 17 | 18 | This library provides a pure Python interface for the [Telegram Bot API](https://core.telegram.org/bots/api). It's compatible with Python versions 2.7, 3.3+ and [PyPy](http://pypy.org/). It also works with [Google App Engine](https://cloud.google.com/appengine). 19 | 20 | In addition to the pure API implementation, this library features a number of high-level classes to make the development of bots easy and straightforward. These classes are contained in the `telegram.ext` submodule. 21 | 22 | You can read more about this fantastic library by visiting its [official documentation](https://github.com/python-telegram-bot/python-telegram-bot). 23 | 24 | ### Contributing 25 | 26 | Feel free to do whatever you want with this project. :-) -------------------------------------------------------------------------------- /.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 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | # Envioriment variable 107 | .env 108 | --------------------------------------------------------------------------------