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

36
LINES

< > BotCompany Repo | #1017462 // Telegram Bot Spike 1 (answers any direct message with "Hello <name>!", OK with token)

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

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (6599L/47K).

!7

lib 1400120 lib 1400115 // JTelegramBot
lib 1400116 lib 1400117 lib 1400118 lib 1400119 // dependencies

import io.fouad.jtb.core.*;
import io.fouad.jtb.core.beans.*;

p-exp {
  S apiToken = trim(loadTextFileMandatory(javaxSecretDir("telegram-bot-token.txt")));

  UpdateHandler updateHandler = new SimpleUpdateHandler {
    public void onMessageReceived(TelegramBotApi api, int id, Message message) {
      pcall {
        print("Got message!");
        print("Text:");
        printIndent("> ", message.getText());
        User u = message.getFrom();
        printStruct("From", ll(u.getId(), u.getFirstName(), u.getLastName(), u.getUsername()));
        print();
        
        api.sendMessage(
          ChatIdentifier.byId(u.getId()), // ChatIdentifier targetChatIdentifier,
          "Hello " + u.getFirstName() + "!",
          null, // ParseMode parseMode,
  	      null, // Boolean disableLinkPreviews,
  	      null, // Boolean silentMessage,
  	      null, // Integer replyToMessageId,
  	      null); // ReplyMarkup replyMarkup
      }
    }
  };
  
  JTelegramBot bot = new JTelegramBot("HelloComputer_bot", apiToken, updateHandler);
  bot.startAsync();
}

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: #1017462
Snippet name: Telegram Bot Spike 1 (answers any direct message with "Hello <name>!", OK with token)
Eternal ID of this version: #1017462/17
Text MD5: f5502dcf250cdfc353e32107ca26c618
Transpilation MD5: cefc6837e1589ba77f557661978da3ef
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:03:59
Source code size: 1209 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 413 / 878
Version history: 16 change(s)
Referenced in: [show references]