{"id":22737942,"url":"https://github.com/simonscholz/telegram-bot-spring","last_synced_at":"2025-07-09T08:05:15.188Z","repository":{"id":80922415,"uuid":"158762532","full_name":"SimonScholz/telegram-bot-spring","owner":"SimonScholz","description":"Implementing a Telegram Messenger Bot with Spring Webflux","archived":false,"fork":false,"pushed_at":"2018-11-28T01:54:24.000Z","size":132,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T04:54:16.645Z","etag":null,"topics":["spring-boot","telegram","telegram-bot","webflux"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimonScholz.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-11-23T00:35:13.000Z","updated_at":"2023-12-01T19:58:01.000Z","dependencies_parsed_at":"2023-03-02T08:45:16.927Z","dependency_job_id":null,"html_url":"https://github.com/SimonScholz/telegram-bot-spring","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SimonScholz/telegram-bot-spring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonScholz%2Ftelegram-bot-spring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonScholz%2Ftelegram-bot-spring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonScholz%2Ftelegram-bot-spring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonScholz%2Ftelegram-bot-spring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimonScholz","download_url":"https://codeload.github.com/SimonScholz/telegram-bot-spring/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonScholz%2Ftelegram-bot-spring/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264419471,"owners_count":23605198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["spring-boot","telegram","telegram-bot","webflux"],"created_at":"2024-12-10T22:18:44.120Z","updated_at":"2025-07-09T08:05:15.182Z","avatar_url":"https://github.com/SimonScholz.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Spring Webflux Telegram Bot image:https://travis-ci.org/SimonScholz/telegram-bot-spring.svg?branch=master[\"Build Status\", link=\"https://travis-ci.org/SimonScholz/telegram-bot-spring\"] image:https://codecov.io/gh/SimonScholz/telegram-bot-spring/branch/master/graph/badge.svg[\"Code Coverage Status\", link=\"https://codecov.io/gh/SimonScholz/telegram-bot-spring\"]\nSimon Scholz (c) 2018\nVersion 1.0, 27.11.2018\n:experimental:\n:icons:\n:toc:\n:toc-title:\n:sectnums:\n:imagesdir: ./img\n:textselfreference: tutorial\n\n[abstract]\nTelegram bot webhook implementation with Spring Boot Webflux\n\n== Technologies\n\n* Spring Boot 2.0 with Webflux\n* Reactive MongoDB\n* Lombok\n* Reactor IO\n* Gradle\n* (Nginx)\n\n== Starting the Spring Boot application\n\nYou can either import the project into the Spring Tool Suite (https://spring.io/tools/sts/all) by using the Buildship (https://github.com/eclipse/buildship/blob/master/docs/user/Installation.md) import wizard and start it from the IDE or simply start the application by running the `bootRun` Gradle task.\n\n[source, console]\n----\n./gradlew bRun\n----\n\n== Using a Webhook\n\nUsually you'd want to use a webhook, if you're providing a rest endpoint like this app does.\n\nThe webhook should point the _/telegram/webhook_ endpoint, e.g., https://{your-domain}/telegram/webhook.\n\n== Sample Update for the webhook\n\n[source, console]\n----\ncurl -H \"Content-Type: application/json\" -X POST -d '{\"update_id\":463166687, \"message\":{\"message_id\":256,\"from\":{\"id\":{your-user-id},\"is_bot\":false,\"first_name\":\"Simon\",\"last_name\":\"Scholz\",\"language_code\":\"en-US\"},\"chat\":{\"id\":{your-chat-id},\"first_name\":\"Simon\",\"last_name\":\"Scholz\",\"type\":\"private\"},\"date\":1519229850,\"text\":\"/now Hamburg\",\"entities\":[{\"offset\":0,\"length\":4,\"type\":\"bot_command\"}]}}' http://localhost:8080/telegram/webhook\n----\n\n=== Set a webhook\n\nA nice way to set the webhook is by using _curl_:\n\n[source, console]\n----\ncurl -F \"url=https://{your-domain}/telegram/webhook\" https://api.telegram.org/bot{your-bots-api-token}/setWebhook\n----\n\nFor a custom ssl certificate(telegram required pem) the following command can be used:\n\n[source, console]\n----\ncurl -F \"url=https://{your-domain}/webhook\" -F \"certificate=@/home/simon/ssl/keystore.pem\" https://api.telegram.org/bot{your api token}/setWebhook\n----\n\nTIP: See https://core.telegram.org/bots/api#setwebhook for further information about setting a webhook.\n\n=== SSL secure the webhook endpoint\n\nTo use a webhook for telegram you need to use port 443 or 8443 with ssl.\nSee \u003c\u003cletsencrypt\u003e\u003e for further information about ssl security for your domain.\n\nThis is also a nice introduction how to achieve that: https://dzone.com/articles/spring-boot-secured-by-lets-encrypt\n\n==== Secure Spring App directly\n\nTo run this Spring Boot application with your own bot you usually have to adjust the application.yml file.\n\n[source, properties]\n----\nserver:\n  port: 443\n  ssl:\n    key-store: /{path-to-file}/keystore.p12 \u003c1\u003e\n    key-store-password: *** your password ***\n    key-store-type: PKCS12\n    key-alias: {your-key-alias}\n----\n\u003c1\u003e See \u003c\u003cletsencrypt\u003e\u003e for *.p12 key store generation\n\n==== Use Nginx for SSL encryption\n\nYou can install Nginx on your server and add the following config files.\n\nhttp.conf.j2\n\n[source, config]\n----\nserver {\n    listen 80 default_server;\n\n    server_name _;\n\n    return 301 https://$host$request_uri; \u003c1\u003e\n}\n----\n\u003c1\u003e Redirect port 80 (http) to port 443 (https)\n\nThen add the following https.conf.j2 Nginx config:\n\n[source, config]\n----\nupstream app-upstream {\n    server localhost:{port}; \u003c1\u003e\n}\n\nserver {\n    listen       443 default ssl;\n    server_name  {{ service_host }};\n\n    #charset koi8-r;\n    #access_log  /var/log/nginx/host.access.log  main;\n\n    ssl_certificate /etc/letsencrypt/live/{{ service_host }}/fullchain.pem;\n    ssl_certificate_key /etc/letsencrypt/live/{{ service_host }}/privkey.pem;\n    ssl_session_cache shared:SSL:10m;\n    ssl_session_timeout 10m;\n    ssl_dhparam /etc/ssl/certs/dhparam.pem;\n\n    ssl_session_tickets off;\n    ssl_stapling on;\n    ssl_stapling_verify on;\n    add_header X-Frame-Options DENY;\n    add_header X-Content-Type-Options nosniff;\n    add_header X-XSS-Protection \"1; mode=block\";\n\n    ssl_prefer_server_ciphers on;\n    ssl_protocols TLSv1.2 TLSv1.3;\n    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;\n    ssl_ecdh_curve secp384r1;\n\n\n    location / {\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header Host $http_host;\n        proxy_set_header X-Forwarded-Proto $scheme;\n        proxy_redirect off;\n        proxy_pass http://app-upstream;\n    }\n}\n----\n\u003c1\u003e Substitute _{port}_ with your server apps port\n\n== Questions\n\nPlease make use of this bot, share your knowledge and adapt it for your needs. \n\n== Contributing\n\nFeedback is highly appreciated. You may open issues, send pull requests or simply contact me.\n\n[[letsencrypt]]\n== Let's Encrypt\n\nAdd ssl certificate to your domain.\n\n=== For Fritz!Box AVM Router\n\nAVM is currently working on a setting for Let's Encrypt and their routers.\n\nSee https://avm.de/fritz-labor/fritz-labor-fuer-fritzbox-7490-und-7590/lets-encrypt/\n\n=== Using certbot\n\n[source, console]\n----\ncd {your home directory}\n\nmkdir certbot\n\ncd certbot\n\nwget https://dl.eff.org/certbot-auto\n\nchmod +x certbot-auto\n\n./certbot-auto certonly -a standalone -d {your domain name -\u003e example.ddns.net}\n\ncd /etc/letsencrypt/live/{your domain name -\u003e example.ddns.net}/\n\nopenssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name telegram-bot -CAfile chain.pem -caname root\n\n----\n\nThe _keystore.p12_ file has to be moved to a location, which can be accessed by the user, which starts the spring boot app service. The `chown -R {username} and chgrp -R {username}` command are helpful here.\n\nThe conversion to a _keystore.p12_ file with _openssl_ is necessary, because spring boot does not work with _*.pem_ files, but with _*.p12_ files.\nSee _server.ssl.key-store_ property in _application.properties_ file of the spring boot application.\n\n\n=== Renew the certificate\n\n[source, console]\n----\n\ncd certbot\n\n./certbot-auto renew\n\ncd /etc/letsencrypt/live/{your domain name -\u003e example.ddns.net}/\n\nopenssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name telegram-bot -CAfile chain.pem -caname root\n----\n\n\n== Sources\n\nhttps://core.telegram.org/bots/api\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonscholz%2Ftelegram-bot-spring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonscholz%2Ftelegram-bot-spring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonscholz%2Ftelegram-bot-spring/lists"}