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

33
LINES

< > BotCompany Repo | #1017467 // Telegram Bot Spike 6 (reacting to channel posts, OK)

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

Download Jar. Uses 12378K of libraries. Click here for Pure Java version (5620L/40K).

1  
!7
2  
3  
!include once #1017511 // Telegram Bots
4  
5  
p-exp {
6  
  fS apiToken = telegramBotToken_mandatory();
7  
8  
  ApiContextInitializer.init();
9  
  TelegramLongPollingBot bot = new TelegramLongPollingBot {
10  
    public S getBotUsername() { ret "HelloComputer_bot"; }
11  
    public S getBotToken() { ret apiToken; }
12  
    
13  
    public void onUpdateReceived(Update update) {
14  
      pcall {
15  
        print("Got update! " + update);
16  
        Message msg = update.getChannelPost();
17  
        if (msg != null && msg.hasText()) {
18  
          S text = msg.getText();
19  
          print("Text: " + text);
20  
          S response = "You typed " + n2(l(text), "character");
21  
          Chat chat = msg.getChat();
22  
          
23  
          new SendMessage sending;
24  
          sending.setText(response);
25  
          sending.setChatId(msg.getChatId());
26  
          sendMessage(sending);
27  
        }
28  
      }
29  
    }
30  
  };
31  
32  
  new TelegramBotsApi().registerBot(bot);
33  
}

Author comment

Began life as a copy of #1017466

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: #1017467
Snippet name: Telegram Bot Spike 6 (reacting to channel posts, OK)
Eternal ID of this version: #1017467/12
Text MD5: fa73b7e4925226007649592880a08bdf
Transpilation MD5: d48d9647e47d6f38ae6a5dd03318d47f
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:14:36
Source code size: 931 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 311 / 731
Version history: 11 change(s)
Referenced in: [show references]