Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

41
LINES

< > BotCompany Repo | #1017463 // Telegram Bot Spike 2 (telling user I'm typing, OK)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (6605L/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  
10  
p-exp {
11  
  S apiToken = trim(loadTextFileMandatory(javaxSecretDir("telegram-bot-token.txt")));
12  
13  
  UpdateHandler updateHandler = new SimpleUpdateHandler {
14  
    public void onMessageReceived(TelegramBotApi api, int _id, Message message) {
15  
      pcall {
16  
        print("Got message!");
17  
        print("Text:");
18  
        printIndent("> ", message.getText());
19  
        User u = message.getFrom();
20  
        printStruct("From", ll(u.getId(), u.getFirstName(), u.getLastName(), u.getUsername()));
21  
        print();
22  
        
23  
        ChatIdentifier id = ChatIdentifier.byId(u.getId());
24  
        
25  
        api.sendChatAction(id, ChatAction.TYPING);
26  
        sleepSeconds(3);
27  
        api.sendMessage(
28  
          id, // ChatIdentifier targetChatIdentifier,
29  
          "Hello " + u.getFirstName() + "!",
30  
          null, // ParseMode parseMode,
31  
  	      null, // Boolean disableLinkPreviews,
32  
  	      null, // Boolean silentMessage,
33  
  	      null, // Integer replyToMessageId,
34  
  	      null); // ReplyMarkup replyMarkup
35  
      }
36  
    }
37  
  };
38  
  
39  
  JTelegramBot bot = new JTelegramBot("HelloComputer_bot", apiToken, updateHandler);
40  
  bot.startAsync();
41  
}

Author comment

Began life as a copy of #1017462

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: #1017463
Snippet name: Telegram Bot Spike 2 (telling user I'm typing, OK)
Eternal ID of this version: #1017463/6
Text MD5: 6f17faf1ee7bef192d42beb02b6c32d1
Transpilation MD5: 923e15215a6a053e3c1ab773110cd92e
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:09:18
Source code size: 1366 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 376 / 934
Version history: 5 change(s)
Referenced in: [show references]