/avatar-bot

Telegram Bot to create Avatars

Primary LanguagePython

Avatar Bot

Build Status codecov

Simple Telegram Bot that sends you avatar images based on simple words you send it. The images are pulled from Adorable Avatars

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Pre-requisites

Any editor of your choice can be used for this application.

  1. Python

    This project has been built with Python 3.7. Ensure that you install this version of Python as outlined in the link provided here

  2. Pip

    This is a package manager for Python applications and will be useful when handling dependencies for this application. Installations instructions can be found in the link int the title.

  3. Pipenv

    An awesome dependency management tool for Python and is highly recommended. This is the preferred tool of choice for this project. This allows use to separate between dev dependencies and dependencies

  4. Docker

    This will be used when containerizing the application for running in a SOA(Service Oriented Architecture). This is used especially when deployment. Allows this application to run in any environment with minimal configuration.

Installing

To get up and running you will need to do the following:

  1. Install dependencies

    Install required dependencies of this project using pipenv, which is the required dependency management tool for this project. to install dependencies, simply use command in your terminal at the root of the project:

    pipenv install

    This will automatically create a virtual environment for you and give further instructions on how to activate it

  2. Configure environment variables for the project.

    This application has been structured in order to be portable. For this to happen, environment variables are used for some configuration settings. Example is a database connection. This is left to the user to setup database connection string in order not to be tied to a specific database. Another example is the port. A reasonable default is used, however, if this default does not suit your needs, a PORT environment variable can be used.

    In order to achieve this, create a .env file at the root of the project ad add these environment variables:

    TOKEN=<TELEGRAM_BOT_TOKEN>
    URL=<URL>
    PORT=7000
    FLASK_ENV=development
    

    These environment variables can then be passed on to the application. Note that the strings in <> are place holders and are used to demonstrate where the values will go for the environment variables

    i. Telegram Bot Token

    To get this token, you will need a Telegram account, which you can sign up here. To create a chat bot on Telegram, you will need to contact the BotFather. The command you need is /newbot:

    botfather

    a sample chat with the BotFather

    It will give you more instructions on how to setup your bot. Once the bot is setup, you will see a token (which is hashed out in the image above). That is the token you will use for the bot and set in the TOKEN environment variable

    ii. Hosting URL

    Once the application is hosted(You can choose whichever platform to host it), you will need to setup the webhook for Telegram to post your messages to. Get the URL that the application will be exposed to and add it as an environment variable (URL=<URL_THAT_IS_EXPOSED_BY_THE_HOSTING_PLATFORM_YOU_PICK>)

    Next, will be to setup the Webhook by running the command:

    python manage.py setup_webhook

    iii. Flask Environment

    The FLASK_ENV environment variable determines the configuration to use. Various configurations are found here For local development, you can use development, for production, it is advised to use production

This is a sample conversion with the resulting bot:

avatar bot

Testing

The application tests can be found under tests directory and are structure in a similar manner to the application code.

Test framework used is Pytest and can be used as follows:

pytest

This will discover all tests under tests directory

In case of running a coverage report simply use:

pytest --cov=app tests/

Will run a coverage report using the plugin pytest-cov

To generate a test report run

coverage html

This will generate a HTML file report that will be stored under coverage directory(This is not pushed to a VCS)

Settings and configuration for coverage can be found in the file .coveragerc

Deployment

Deployment can be done on any hosting platform that supports running a Python application. In this case, Heroku has been used. However, any other hosting platform can be used. This goes as far as setting up a Dockerfile for those wishing to deploy this as a micro-service in a larger Service Oriented Architecture.

Built With

  1. Python - Source language
  2. Pytest - Python Test Framework
  3. Flask - Python Web Framework

Contributing

Please read contributing guide for more information

Versioning

We use SemVer for versioning.