Code Monkey home page Code Monkey logo

symfonylive-berlin-bot's Introduction

SymfonyLive Berlin Telegram Chatbot

Telegram Chatbot for SymfonyLive Berlin 2023

Find it on Telegram: @SymfonyLiveBerlinBot

Requirements

Setting up ngrok

The Telegram bot will communicate with our application to process messages and reply to them. This requires a websocket connection that is reachable from the outside world, i.e. the internet. This can be achieved by deploying the application, e.g. using Symfony Cloud, or exposing the local environment through an HTTPS tunnel service like serveo or ngrok.

  1. Download and install the ngrok client
  2. Sign up for a private ngrok account on https://ngrok.com
  3. Go to the Auth section in the dashboard and follow the instructions for setting the auth token
  4. Run ngrok: ngrok http https://localhost:8000 The URL https://localhost:8000 refers to our local Symfony Server, so be careful to update the port info if necessary.

When you run ngrok, you will see Forwarding addresses like https://abcd5678.ngrok.io. You will need this value for the WEBHOOK_BASE_URL environment variable. Alternatively you can copy .env as .env.local and set the value there.

Setting up the Telegram bot

You will need to set up a Telegram bot to interact with. You can do this through Telegram by sending a message to a bot @BotFather and following the instructions. Alternatively you can use the CLI as described in the link above.

Once you finished setting up the bot you will get a long message with an auth token that looks something like: 1234567890:ABCD7890efgh1234IJKL5678mnop11223-3.

This token is used for the environment variable TELEGRAM_TOKEN.

Setting up the database

Set up a database using a platform supported by Doctrine ORM, e.g. MySQL, PostgreSQL or SQLite3. Set the database DSN using the environment variable DATABASE_URL or by setting the value in our .env.local. You can find an example for an SQLite3 DSN in the .env file, which should be suitable for first development steps.

Setup

To set up this demo we need to create a telegram bot and connect our local environment to it (see sections above).

  1. Clone the repository and go into the project root:

    git clone [email protected]:chr-hertel/symfonylive-berlin-bot.git
    cd symfonylive-berlin-bot
  2. Install the dependencies

    composer install
  3. Set up ngrok and start the tunnel

    ngrok http https://localhost:8000
  4. Set up Telegram bot (only necessary on first run)

  5. Set up the database and environment variables

    • DATABASE_URL - see .env for examples
    • TELEGRAM_TOKEN - token provided by BotFather (eg. 1234567890:ABCD7890efgh1234IJKL5678mnop11223-3)
    • WEBHOOK_BASE_URL - ngrok base url (eg. https://abcd5678.ngrok.io)
  6. Start the development server using the Symfony CLI

    symfony serve --detach
  7. Set up the entities

    bin/console doctrine:database:create
    bin/console doctrine:schema:create
    bin/console doctrine:fixtures:load # Schedule of 2019
  8. Load schedule of 2022 (optional)

    bin/console app:schedule:crawl
  9. Set up the webhook & menu (only necessary once)

    bin/console app:webhook:register
    bin/console app:command:register

Testing

Relevant tools

  • PHP CS Fixer

    php vendor/bin/php-cs-fixer fix
    
  • PHPStan

    php vendor/bin/phpstan analyse
    
  • PHPUnit

    # without coverage
    php bin/phpunit
    
    # with coverage, but without functional tests
    XDEBUG_MODE=coverage php bin/phpunit --coverage-html=public/phpunit --exclude=functional
    
  • Infection (not executed in pipeline)

    php vendor/bin/infection
    

Pipeline

Pipeline is executed with GitHub Actions on Pull Requests.

You can simulate locally with:

bin/check

Deployment

Deployment is executed with GitHub Action on push on main branch using Deployer.

Development

If you're using PhpStorm and you want to play around with the WebHook controller or Telegram Bot API, see HTTP files:

  • Create http-client-private.env.json file with your bot token & your chat id:

    {
      "dev": {
         "bot-token": "bot:TOKEN",
         "chat-id": "123456789"
      }
    }
  • Now you can use the example files, to interact with both applications:

    • Telegram Bot API: telegram-bot-api.http
    • ChatBot Webhook: chatbot-webhook.http

symfonylive-berlin-bot's People

Contributors

chr-hertel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.