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).

!7

!include once #1017511 // Telegram Bots

p-exp {
  fS apiToken = telegramBotToken_mandatory();

  ApiContextInitializer.init();
  TelegramLongPollingBot bot = new TelegramLongPollingBot {
    public S getBotUsername() { ret "HelloComputer_bot"; }
    public S getBotToken() { ret apiToken; }
    
    public void onUpdateReceived(Update update) {
      pcall {
        print("Got update! " + update);
        Message msg = update.getChannelPost();
        if (msg != null && msg.hasText()) {
          S text = msg.getText();
          print("Text: " + text);
          S response = "You typed " + n2(l(text), "character");
          Chat chat = msg.getChat();
          
          new SendMessage sending;
          sending.setText(response);
          sending.setChatId(msg.getChatId());
          sendMessage(sending);
        }
      }
    }
  };

  new TelegramBotsApi().registerBot(bot);
}

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: 411 / 1015
Version history: 11 change(s)
Referenced in: [show references]