Giter VIP home page Giter VIP logo

exampletelegrambot's Introduction

Example Telegram Bot Deploy

Build Status License: MIT Quality Gate Status Reliability Rating Security Rating Maintainability Rating Bugs

This repository contains an example of telegram bot written in Java (11 and above)

Current version supports the following commands:

  • /help - Displays help about all or specified command
  • /whoami - Displays information about the person who wrote the command: User Id, Name and chat type
  • /start - The default bot command, shows greeting message
  • /menu - Shows example of Inline Menu with buttons

Configuration

Configuration is supplied through Environment Variables:

EXAMPLE_TG_BOT_USERNAME=ExampleTelegramBot # The bot name from BotFather
EXAMPLE_TG_BOT_TOKEN=123455:abcd.. # The token from BotFather
EXAMPLE_TG_BOT_ADMIN_IDS=123456 # User ids separated by comma, allowing them to access /menu (You can obtain that id by typing /whoami)

Click here to talk to BotFather

There are multiple ways to start this example, here are two:

Docker with docker-compose

You can run this example with docker.

First create new file called .env with the content mentioned Environment Variables above.

  1. Create and start the container
    docker-compose up -d
  2. Check the logs for errors
    docker-compose logs
  3. If bot is working correctly you should see the following logs
    Attaching to example_telegram_bot
    example_telegram_bot | [20:30:06] [INFO] Main: Initializing ** Your bot name here** ...
    example_telegram_bot | [20:30:06] [INFO] Main: Authorized admin ids: [**Your ids here**]
    example_telegram_bot | [20:30:07] [INFO] Main: Initialization done
  4. If you want to stop the bot
    docker-compose down

Source

Alternatively you can run the example from source

  1. Clone the repository
    git clone https://github.com/UnAfraid/ExampleTelegramBot.git
  2. Build the source
    # For Windows
    gradlew.bat installDist
    
    # For Linux/Mac
    ./gradlew installDist
  3. Run the bot
    # Set Environment Variables
    
    # For Windows
    set EXAMPLE_TG_BOT_USERNAME=ExampleTelegramBot # The bot name from BotFather
    set EXAMPLE_TG_BOT_TOKEN=123455:abcd.. # The token from BotFather
    set EXAMPLE_TG_BOT_ADMIN_IDS=123456 # User ids separated by comma, allowing them to access /menu (You can obtain that id by typing /whoami)
    
    # For Linux/Mac
    export EXAMPLE_TG_BOT_USERNAME=ExampleTelegramBot # The bot name from BotFather
    export EXAMPLE_TG_BOT_TOKEN=123455:abcd.. # The token from BotFather
    export EXAMPLE_TG_BOT_ADMIN_IDS=123456 # User ids separated by comma, allowing them to access /menu (You can obtain that id by typing /whoami)
    
    # Navigate to the bot build directory
    cd build/install/ExampleTelegramBot
    
    # Run the bot
    java --add-opens java.base/java.lang=ALL-UNNAMED -jar ExampleTelegramBot.jar
  4. If bot is working correctly you should see the following logs
    [20:30:06] [INFO] Main: Initializing ** Your bot name here** ...
    [20:30:06] [INFO] Main: Authorized admin ids: [**Your ids here**]
    [20:30:07] [INFO] Main: Initialization done

exampletelegrambot's People

Contributors

unafraid 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.