Download Jar. Uses 3874K of libraries. Click here for Pure Java version (6616L/47K).
1 | !7 |
2 | |
3 | lib 1400120 lib 1400115 // JTelegramBot |
4 | lib 1400116 lib 1400117 lib 1400118 lib 1400119 // dependencies |
5 | |
6 | import io.fouad.jtb.core.*; |
7 | import io.fouad.jtb.core.enums.*; |
8 | import io.fouad.jtb.core.beans.*; |
9 | import io.fouad.jtb.core.builders.*; |
10 | |
11 | p-exp { |
12 | S apiToken = trim(loadTextFileMandatory(javaxSecretDir("telegram-bot-token.txt"))); |
13 | |
14 | UpdateHandler updateHandler = new SimpleUpdateHandler { |
15 | public void onMessageReceived(TelegramBotApi api, int _id, Message message) { |
16 | pcall { |
17 | print("Got message!"); |
18 | print("Text:"); |
19 | printIndent("> ", message.getText()); |
20 | User u = message.getFrom(); |
21 | printStruct("From", ll(u.getId(), u.getFirstName(), u.getLastName(), u.getUsername())); |
22 | print(); |
23 | |
24 | ChatIdentifier id = ChatIdentifier.byId(u.getId()); |
25 | |
26 | api.sendChatAction(id, ChatAction.TYPING); |
27 | sleepSeconds(3); |
28 | api.sendMessage( |
29 | id, // ChatIdentifier targetChatIdentifier, |
30 | "Hello " + u.getFirstName() + "!", |
31 | null, // ParseMode parseMode, |
32 | null, // Boolean disableLinkPreviews, |
33 | null, // Boolean silentMessage, |
34 | null, // Integer replyToMessageId, |
35 | null); // ReplyMarkup replyMarkup |
36 | } |
37 | } |
38 | }; |
39 | |
40 | JTelegramBot bot = new JTelegramBot("HelloComputer_bot", apiToken, updateHandler); |
41 | bot.startAsync(); |
42 | |
43 | long chatID = -1001303287441L; |
44 | print("Chat: " + ApiBuilder.api(bot).getChat() |
45 | //.byChatUsername("Hello_Computer") |
46 | .byChatId(chatID) |
47 | .execute()); |
48 | |
49 | bot.sendMessage(ChatIdentifier.byId(chatID), |
50 | "Hello channel", null, null, null, null, null); |
51 | } |
Began life as a copy of #1017464
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1017465 |
Snippet name: | Telegram Bot Spike 4 (send msg to channel, OK) |
Eternal ID of this version: | #1017465/5 |
Text MD5: | e6bf21472154b26aa0ca1e74f929bb87 |
Transpilation MD5: | 91d3b5ea95239bfb344a480edcec5d40 |
Author: | stefan |
Category: | javax / networking |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-07-23 14:48:44 |
Source code size: | 1681 bytes / 51 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 472 / 1011 |
Version history: | 4 change(s) |
Referenced in: | [show references] |