Giter Club home page Giter Club logo

telegram-bot-1's Introduction

Dmi Weather Telegram Bot

This Telegram bot can be used to get the weather forecast graphs for your desired city from www.dmi.dk.

How to use this Telegram Bot

This bot can be used by clicking on telegram.me/dmi_weather_bot or @dmi_weather_bot in your telegram app. After doing this you’ll get a description of the bot and can directly start using it and send commands.

More information concerning Telegram Bots can be found here: https://core.telegram.org/bots

Reasons for using this Telegram Bot

Personally I really like the clearly represented weather forecast graphs, which are provided by www.dmi.dk, but on a mobile device they are not easy to reach with the browser and I am not pleased by current apps for this service. So by implementing this bot I got the chance to really get the raw graphs, which saves my time, system resources on my mobile device and data volume from my mobile provider.

Tutorial

Creating a new Telegram Bot

In order to create a new bot you have to talk with @BotFather. There you can use several commands to create and configure your own bot.

Sending /help to the @BotFather gives an overview about the commands. To create a new bot the /newbot command can be used.

Configure the Application

To run this Spring Boot application with your own bot you usually have to adjust the application.properties file. (https://github.com/SimonScholz/telegram-bot/blob/master/telegram-bot/src/main/resources/application.properties)

bot.api-key=97307424:AAEDj2IXFDEEYfQ6SY_Ma0W_CHu1mUmQ3h8
server.port=8080

The bot.api-key property has to be changed to your own bot token and you might want to change the server.port property as well, e.g., to port 80.

By sending the /token command to the @BotFather and selecting your bot, you’ll get the token, which has to be placed in the application.properties as bot.api-key property value.

Starting the Spring Boot application

You can either import the project into the Spring Tool Suite (https://spring.io/tools/sts/all) and start it from the IDE or simply start the application by running the bootRun Gradle task.

// unix
telegram-bot > ./gradlew bootRun

// win
telegram-bot > gradlew.bat bootRun

Use the Application

Once the application is running either from the IDE or with Gradle you can test it by navigating to http://localhost:8080/poll, which is used to poll your messages/commands.

Currently 4 commands are supported:

  • /now {City name} - Get the current day overview image from dmi.dk

  • /week {City name} - Get the week overview image from dmi.dk

  • /en {german text} - translates german to english

  • /de {english text} - translates english to german

When you send one of these commands to your bot and then open http://localhost:8080/poll the Spring Boot application will try to poll your commands and send appropriate answers to the chat with your bot.

Using a Webhook

Usually you’d want to use a webhook, if you’re providing a rest endpoint like this app does.

The webhook should point the /webhook endpoint, e.g., http://localhost:8080/webhook.

Note
You’ll have to substitute http://localhost:8080/webhook with {your.server.domain}/webhook, since the telegram bot won’t be able to reach the localhost of your machine.

A nice way to set the webhook is by using curl:

curl https://api.telegram.org/bot{your api token}/setWebhook -F "url=https://{your-domain}/webhook"
Tip
See https://core.telegram.org/bots/api#setwebhook for further information about setting a webhook.

Technologies

  • pengrad java telegram bot api

  • Spring Boot

  • Lombok

  • RxJava 2.x

  • Retrofit

  • Gradle

  • H2 Database

Questions

Please make use of this bot, share your knowledge and adapt it for your needs.

Contributing

Feedback is highly appreciated. You may open issues, send pull requests or simply contact me.

telegram-bot-1's People

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.