Download Jar. Uses 12378K of libraries. Click here for Pure Java version (9978L/71K).
1 | !7 |
2 | |
3 | !include once #1017511 // Telegram Bots |
4 | |
5 | p { |
6 | fS apiToken = telegramBotToken_mandatory(); |
7 | |
8 | botInit(); |
9 | |
10 | ApiContextInitializer.init(); |
11 | TelegramLongPollingBot bot = new TelegramLongPollingBot { |
12 | public S getBotUsername() { ret "HelloComputer_bot"; } |
13 | public S getBotToken() { ret apiToken; } |
14 | |
15 | public void onUpdateReceived(Update update) { |
16 | pcall { |
17 | print("Got update! " + update); |
18 | Message msg = update.getMessage(); //update.getChannelPost(); |
19 | logQuotedWithDate(telegramFullUpdatesLogFile(), str(update)); |
20 | if (msg != null && msg.hasText()) { |
21 | S text = msg.getText(); |
22 | print("Incoming text: " + text); |
23 | logStructure(telegramLogFile(), litorderedmap( |
24 | type := 'heard, |
25 | date := localDateWithMilliseconds(), |
26 | +text)); |
27 | S response; |
28 | try { |
29 | response = makeResponse(text, msg); |
30 | } catch e { |
31 | printStackTrace(e); |
32 | response = exceptionToStringShort(e); |
33 | } |
34 | response = rtrim(response); |
35 | if (empty(response)) ret; |
36 | Chat chat = msg.getChat(); |
37 | |
38 | logStructure(telegramLogFile(), litorderedmap( |
39 | type := 'sent, |
40 | date := localDateWithMilliseconds(), |
41 | toChatID := msg.getChatId(), |
42 | text := response)); |
43 | |
44 | new SendMessage sending; |
45 | sending.setText(response); |
46 | sending.setChatId(msg.getChatId()); |
47 | sendMessage(sending); |
48 | } |
49 | } |
50 | } |
51 | }; |
52 | |
53 | new TelegramBotsApi api; |
54 | api.registerBot(bot); |
55 | } |
56 | |
57 | static S makeResponse(fS s, Message msg) { |
58 | if (eqic(s, "whoami")) { |
59 | User from = msg.getFrom(); |
60 | if (from == null) ret "idk"; |
61 | ret msg.getFrom().getId() + " / " + msg.getFrom().getUserName(); |
62 | } |
63 | |
64 | if (eqic(s, "fullmsg")) |
65 | ret str(msg); |
66 | |
67 | //ret "You typed " + n2(l(s), "character"); |
68 | |
69 | ret lines(map tok_dropAllCurlyBrackets(pnlEmits(r { ai_askForUnknownWordTypes(s) }))); |
70 | } |
71 | |
72 | svoid botInit { |
73 | dm_useLocallyCopiedMechLists(); |
74 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1017505 |
Snippet name: | Telegram Bot asking for word types (older) |
Eternal ID of this version: | #1017505/14 |
Text MD5: | 30f24c989c9caa73dec9d656e1dc53f9 |
Transpilation MD5: | f47847e9f691877f9f56eb513237e415 |
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-25 11:58:54 |
Source code size: | 2130 bytes / 74 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 497 / 1168 |
Version history: | 13 change(s) |
Referenced in: | [show references] |