{"id":18665414,"url":"https://github.com/kikimarik/tgbot-java-httpserver","last_synced_at":"2025-06-17T23:36:00.935Z","repository":{"id":102997268,"uuid":"407835233","full_name":"kikimarik/tgbot-java-httpserver","owner":"kikimarik","description":null,"archived":false,"fork":false,"pushed_at":"2021-10-30T22:35:50.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T05:32:05.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kikimarik.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2021-09-18T10:58:55.000Z","updated_at":"2024-02-03T18:26:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"0c6f3e03-21fb-4a79-bbff-930ba51f347d","html_url":"https://github.com/kikimarik/tgbot-java-httpserver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kikimarik/tgbot-java-httpserver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikimarik%2Ftgbot-java-httpserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikimarik%2Ftgbot-java-httpserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikimarik%2Ftgbot-java-httpserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikimarik%2Ftgbot-java-httpserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kikimarik","download_url":"https://codeload.github.com/kikimarik/tgbot-java-httpserver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kikimarik%2Ftgbot-java-httpserver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260458495,"owners_count":23012494,"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":[],"created_at":"2024-11-07T08:27:41.238Z","updated_at":"2025-06-17T23:35:55.923Z","avatar_url":"https://github.com/kikimarik.png","language":"Java","readme":"# Example RunBots.class\n\n```java\npackage usage;\n\nimport api.Client;\nimport api.entities.ApiMethodDTO;\nimport api.entities.methods.SendLocation;\nimport api.entities.methods.SendMessage;\nimport api.entities.types.InlineKeyboardButton;\nimport api.entities.types.reply.InlineKeyboardMarkup;\nimport base.*;\nimport models.BotEventEntity;\nimport models.types.CallbackQuery;\nimport models.types.ChatMemberUpdated;\nimport models.types.Message;\n\nimport java.security.NoSuchAlgorithmException;\nimport java.util.*;\n\n/**\n * Run bot examples servers on tcp-ports 2220, 2221 and 2222\n */\npublic class RunBots {\n    public static void main(String[] args) throws NoSuchAlgorithmException {\n        RunBots.runTwoBotsFromPull();\n        RunBots.runTextMessageReaderBot();\n        RunBots.runFindLocationBot();\n    }\n\n    private static void runTextMessageReaderBot() throws NoSuchAlgorithmException {\n        String token = \"2003365903:AAENDWj08cwczI4A1H9i1jp7sPP_pGNmxdI\";\n        Bot bot = new Bot(token);\n        bot.setEvents(new PriorityQueue\u003c\u003e(Comparator.comparingInt(BotEvent::getId))); // example with priority queue\n        System.out.println(\"Path to text message reader bot webhooks: \" + bot.getPathUri() + \"\\n\");\n        HashMap\u003cString, BotEventListener\u003e listeners = new HashMap\u003c\u003e();\n        listeners.put(\"receiveTextMessage\", new BotEventListener() {\n            private Message message;\n\n            @Override\n            public void setEntity(BotEventEntity entity) {\n                this.message = (Message) entity;\n            }\n\n            @Override\n            public void exec() {\n                System.out.println(this.message.printTextMessage());\n                Client client = Client.getInstance();\n                String response = client.send(token, new ApiMethodDTO(\n                        \"sendMessage\",\n                        new SendMessage(this.message.chat.id, \"I received you message: \" + message.text).toString()\n                ));\n                System.out.println(response);\n            }\n        });\n        Server server = new Server(bot, 2222);\n        BotBootstrap bootstrap = new BotBootstrap(server, bot, listeners);\n        bootstrap.up();\n    }\n\n    private static void runFindLocationBot() throws NoSuchAlgorithmException {\n        String token = \"2003365903:AAENDWj08cwczI4A1H9i1jp7sPP_pGNmxdI\";\n        Bot bot = new Bot(token);\n        System.out.println(\"Path to text message reader bot webhooks: \" + bot.getPathUri() + \"\\n\");\n        HashMap\u003cString, BotEventListener\u003e listeners = new HashMap\u003c\u003e();\n        listeners.put(\"receiveTextMessage\", new BotEventListener() {\n            private Message message;\n\n            @Override\n            public void setEntity(BotEventEntity entity) {\n                this.message = (Message) entity;\n            }\n\n            @Override\n            public void exec() {\n                Client client = Client.getInstance();\n                SendMessage dto = new SendMessage(this.message.chat.id, \"Chose you city or send me your location.\");\n                dto.reply_markup = new InlineKeyboardMarkup(new InlineKeyboardButton[]{\n                        new InlineKeyboardButton(\"Brussels\", \"1\"),\n                        new InlineKeyboardButton(\"London\", \"2\"),\n                        new InlineKeyboardButton(\"Vienna\", \"3\")\n                });\n                String response = client.send(token, new ApiMethodDTO(\n                        \"sendMessage\",\n                        dto.toString()\n                ));\n                System.out.println(response);\n            }\n        });\n        listeners.put(\"receiveData\", new BotEventListener() {\n            private CallbackQuery callbackQuery;\n\n            @Override\n            public void setEntity(BotEventEntity entity) {\n                this.callbackQuery = (CallbackQuery) entity;\n            }\n\n            @Override\n            public void exec() {\n                Client client = Client.getInstance();\n                HashMap\u003cFloat, Float\u003e londonAddresses = new HashMap\u003c\u003e();\n                londonAddresses.put(57.14284119897725f, -2.0966693015555022f);\n                londonAddresses.put(50.822923531958025f, -0.14588297444286305f);\n\n                HashMap\u003cFloat, Float\u003e brusselsAddresses = new HashMap\u003c\u003e();\n                brusselsAddresses.put(50.83683564279223f, 4.358317112064303f);\n\n                HashMap\u003cFloat, Float\u003e viennaAddresses = new HashMap\u003c\u003e();\n                viennaAddresses.put(48.20712383146376f, 16.371795298497297f);\n\n                ArrayList\u003cSendLocation\u003e sendLocationList = new ArrayList\u003c\u003e();\n\n                switch (this.callbackQuery.data) {\n                    case \"1\":\n                        for (Map.Entry\u003cFloat, Float\u003e location : brusselsAddresses.entrySet()) {\n                            sendLocationList.add(new SendLocation(\n                                    this.callbackQuery.message.chat.id,\n                                    location.getKey(),\n                                    location.getValue()\n                            ));\n                        }\n                        break;\n                    case \"2\":\n                        for (Map.Entry\u003cFloat, Float\u003e location : londonAddresses.entrySet()) {\n                            sendLocationList.add(new SendLocation(\n                                    this.callbackQuery.message.chat.id,\n                                    location.getKey(),\n                                    location.getValue()\n                            ));\n                        }\n                        break;\n                    case \"3\":\n                        for (Map.Entry\u003cFloat, Float\u003e location : viennaAddresses.entrySet()) {\n                            sendLocationList.add(new SendLocation(\n                                    this.callbackQuery.message.chat.id,\n                                    location.getKey(),\n                                    location.getValue()\n                            ));\n                        }\n                        break;\n                    default:\n                        String response = client.send(token, new ApiMethodDTO(\n                                \"sendMessage\",\n                                new SendMessage(\n                                        this.callbackQuery.message.chat.id,\n                                        \"There is no store in your city.\"\n                                ).toString()\n                        ));\n                        System.out.println(response);\n                }\n\n                for (SendLocation dto : sendLocationList) {\n                    String response = client.send(token, new ApiMethodDTO(\n                            \"sendLocation\",\n                            dto.toString()\n                    ));\n                    System.out.println(response);\n                }\n            }\n        });\n        listeners.put(\"receiveChatMember\", new BotEventListener() {\n            private ChatMemberUpdated member;\n\n            @Override\n            public void setEntity(BotEventEntity entity) {\n                this.member = (ChatMemberUpdated) entity;\n            }\n\n            @Override\n            public void exec() {\n                Client client = Client.getInstance();\n                if (this.member.invite_link.is_primary || this.member.invite_link.is_revoked) {\n                    String response = client.send(token, new ApiMethodDTO(\n                            \"sendMessage\",\n                            new SendMessage(\n                                    this.member.chat.id,\n                                    \"Hello! I could help to find Apple store in your region.\"\n                            ).toString()\n                    ));\n                    System.out.println(response);\n                }\n            }\n        });\n        listeners.put(\"receiveLocation\", new BotEventListener() {\n            private Message message;\n            private static final Double MAX_RELEVANT_DISTANCE = 200d;\n\n            @Override\n            public void setEntity(BotEventEntity entity) {\n                this.message = (Message) entity;\n            }\n\n            @Override\n            public void exec() {\n                if (this.message == null) {\n                    return;\n                }\n                Client client = Client.getInstance();\n\n                HashMap\u003cFloat, Float\u003e addresses = new HashMap\u003c\u003e();\n                addresses.put(57.14284119897725f, -2.0966693015555022f);\n                addresses.put(50.822923531958025f, -0.14588297444286305f);\n                addresses.put(50.83683564279223f, 4.358317112064303f);\n                addresses.put(48.20712383146376f, 16.371795298497297f);\n\n                Float lat = this.message.location.latitude;\n                Float lon = this.message.location.longitude;\n\n                double distance;\n                double optimalDistance = MAX_RELEVANT_DISTANCE;\n                SendLocation dto = null;\n                for (Map.Entry\u003cFloat, Float\u003e address : addresses.entrySet()) {\n                    distance = 111.2 * Math.sqrt(\n                            (lon - address.getValue())\n                                    * (lon - address.getValue())\n                                    + (lat - address.getKey())\n                                    * Math.cos(Math.PI * lon / 180)\n                                    * (lat - address.getKey())\n                                    * Math.cos(Math.PI * lon / 180)\n                    );\n                    if (distance \u003c optimalDistance) {\n                        dto = new SendLocation(\n                                this.message.from.id,\n                                address.getKey(),\n                                address.getValue()\n                        );\n                        optimalDistance = distance;\n                    }\n                }\n\n                String response;\n                String text = \"There is no store in your city.\";\n                if (dto != null) {\n                    response = client.send(token, new ApiMethodDTO(\n                            \"sendLocation\",\n                            dto.toString()\n                    ));\n                    System.out.println(response);\n                    text = \"I found nearest Apple store in \" + optimalDistance + \" km of you\";\n                }\n                response = client.send(token, new ApiMethodDTO(\n                        \"sendMessage\",\n                        new SendMessage(\n                                this.message.chat.id,\n                                text\n                        ).toString()\n                ));\n\n                System.out.println(response);\n            }\n        });\n        Server server = new Server(bot, 2221);\n        BotBootstrap bootstrap = new BotBootstrap(server, bot, listeners);\n        bootstrap.up();\n    }\n\n    private static void runTwoBotsFromPull() throws NoSuchAlgorithmException {\n        Bot firstBot = new Bot(\"1958107039:AAHok6pZJH0iKwOTBaeDBftNz6-sS7_7sgg\");\n        Bot secondBot = new Bot(\"2003365903:AAENDWj08cwczI4A1H9i1jp7sPP_pGNmxdI\");\n        System.out.println(\"Path to the first bot webhooks: \" + firstBot.getPathUri() + \"\\n\");\n        System.out.println(\"Path to the second bot webhooks: \" + secondBot.getPathUri() + \"\\n\");\n        LinkedList\u003cBot\u003e bots = new LinkedList\u003c\u003e(List.of(firstBot, secondBot));\n\n        BotEventListener messageEvent = new BotEventListener() {\n            private BotEventEntity entity;\n\n            @Override\n            public void setEntity(BotEventEntity entity) {\n                this.entity = entity;\n            }\n\n            @Override\n            public void exec() {\n                // Past your code here\n                System.out.println(this.entity.toString());\n            }\n        };\n        HashMap\u003cString, BotEventListener\u003e listeners = new HashMap\u003c\u003e();\n        listeners.put(\"receiveTextMessage\", messageEvent);\n\n        HashMap\u003cBot, HashMap\u003cString, BotEventListener\u003e\u003e pool = new HashMap\u003c\u003e();\n        pool.put(firstBot, listeners);\n        pool.put(secondBot, listeners);\n\n        Server server = new Server(bots, 2220);\n        BotBootstrap bootstrap = new BotBootstrap(server, pool);\n        bootstrap.up();\n    }\n}\n```\n\nYou can add this file to the `usage` package to learn our examples.\nIf you want to run this code on you machine you\nneed to inject this dependency to `Maven` via `pom.xml`\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.telegram.bot.client.lib\u003c/groupId\u003e\n    \u003cartifactId\u003etgbot-java-httpclient\u003c/artifactId\u003e\n    \u003cversion\u003e1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\nAlso, you must replace example tokens for your real tokens. \nAfter that run 2 commands:\n```shell\nmvn install:install-file -Dfile=lib/tgbot-java-httpclient-1.0.jar -DgroupId=com.telegram.bot.client.lib -DartifactId=tgbot-java-httpclient -Dversion=1.0 -Dpackaging=jar\n```\n```shell\nmvn clean compile exec:java -Dexec.mainClass=usage.RunBots\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkikimarik%2Ftgbot-java-httpserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkikimarik%2Ftgbot-java-httpserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkikimarik%2Ftgbot-java-httpserver/lists"}