当前位置: 首页>>代码示例>>Java>>正文


Java Message类代码示例

本文整理汇总了Java中se.anyro.tgbotapi.types.Message的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Message类属于se.anyro.tgbotapi.types包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
    
    User user = message.from;
    UserProfilePhotos userProfilePhotos = api.getUserProfilePhotos(user.id);

    StringBuilder builder = new StringBuilder();
    if (user.username != null) {
        builder.append("@").append(user.username).append('\n');
    }
    builder.append("Id: ").append(user.id).append('\n');
    builder.append("First: ").append(user.first_name).append('\n');
    if (user.last_name != null) {
        builder.append("Last: ").append(user.last_name).append('\n');
    }
    builder.append("Photos: ").append(userProfilePhotos.total_count);
    
    PhotoSize photo = userProfilePhotos.photos[0][0];
    api.sendPhoto(message.chat.id, photo.file_id, builder.toString(), 0, null);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:21,代码来源:Profile.java

示例2: sendMessage

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
/**
 * @see <a href="https://core.telegram.org/bots/api#sendmessage">Official documentation of sendMessage</a>
 */
public Message sendMessage(long chatId, String text, ParseMode parseMode, boolean disablePreview, int replyTo,
        ReplyMarkup replyMarkup) throws IOException {
    text = urlEncode(text);
    StringBuilder command = new StringBuilder(SEND_MESSAGE);
    command.append("chat_id=").append(chatId);
    command.append("&text=").append(text);
    if (parseMode != null) {
        command.append("&parse_mode=").append(parseMode.VALUE);
    }
    if (disablePreview) {
        command.append("&disable_web_page_preview=True");
    }
    if (disableNotification) {
        command.append("&disable_notification=true");
    }
    if (replyTo > 0) {
        command.append("&reply_to_message_id=").append(replyTo);
    }
    if (replyMarkup != null) {
        command.append("&reply_markup=").append(urlEncode(GSON.toJson(replyMarkup)));
    }
    return callMethod(command.toString(), Message.class);
}
 
开发者ID:nadam,项目名称:tg-bot-api,代码行数:27,代码来源:TgBotApi.java

示例3: sendPhoto

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
/**
 * @see <a href="https://core.telegram.org/bots/api#sendphoto">Official documentation of sendPhoto</a>
 */
public Message sendPhoto(String channel, String photo, String caption, int replyTo, ReplyMarkup replyMarkup)
        throws IOException {
    StringBuilder command = new StringBuilder(SEND_PHOTO).append('?');
    command.append("chat_id=").append(channel);
    command.append("&photo=").append(photo);
    if (caption != null) {
        command.append("&caption=").append(urlEncode(caption));
    }
    if (disableNotification) {
        command.append("&disable_notification=true");
    }
    if (replyTo > 0) {
        command.append("&reply_to_message_id=").append(replyTo);
    }
    if (replyMarkup != null) {
        command.append("&reply_markup=").append(urlEncode(GSON.toJson(replyMarkup)));
    }
    return callMethod(command.toString(), Message.class);
}
 
开发者ID:nadam,项目名称:tg-bot-api,代码行数:23,代码来源:TgBotApi.java

示例4: sendDocument

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
/**
 * @see <a href="https://core.telegram.org/bots/api#senddocument">Official documentation of sendDocument</a>
 */
public Message sendDocument(String channel, String document, String caption, int replyTo, ReplyMarkup replyMarkup)
        throws IOException {
    StringBuilder command = new StringBuilder(SEND_DOCUMENT).append('?');
    command.append("chat_id=").append(channel);
    command.append("&document=").append(document);
    if (caption != null) {
        command.append("&caption=").append(urlEncode(caption));
    }
    if (disableNotification) {
        command.append("&disable_notification=true");
    }
    if (replyTo > 0) {
        command.append("&reply_to_message_id=").append(replyTo);
    }
    if (replyMarkup != null) {
        command.append("&reply_markup=").append(urlEncode(GSON.toJson(replyMarkup)));
    }
    return callMethod(command.toString(), Message.class);
}
 
开发者ID:nadam,项目名称:tg-bot-api,代码行数:23,代码来源:TgBotApi.java

示例5: doPost

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

      resp.setStatus(200);

try {
          Update update = api.parseFromWebhook(req.getReader());
          if (!update.isMessage()) {
              return;
          }
          Message message = update.message;
          User forwardFrom = message.forward_from;
          User user = forwardFrom;
          if (forwardFrom == null) {
              // Not forwarded so show info of the sender instead
              user = message.from;
          }
          StringBuilder builder = new StringBuilder();
          if (user.username != null) {
              builder.append("@").append(user.username).append('\n');
          }
          builder.append("Id: ").append(user.id).append('\n');
          builder.append("First: ").append(user.first_name).append('\n');
          if (user.last_name != null) {
              builder.append("Last: ").append(user.last_name).append('\n');
          }
          if (user.language_code != null) {
              builder.append("Lang: ").append(user.language_code).append('\n');
          }
          // Separate message for easy copy/paste on mobile
          if (message.from.id == OWNER && forwardFrom != null) {
              api.sendMessage(OWNER, String.valueOf(user.id));
          }
          api.sendMessage(message.from.id, builder.toString());
      } catch (Exception e) {
          api.debug(e);
      }
  }
 
开发者ID:nadam,项目名称:userinfobot,代码行数:39,代码来源:UserInfoServlet.java

示例6: handleCallbackQuery

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
public void handleCallbackQuery(CallbackQuery callbackQuery) {
    try {
        String data = callbackQuery.data;
        Message message = callbackQuery.message;

        CallbackData command = CallbackData.valueOf(data);

        switch (command) {
        case EDIT:
            if (message.text.length() > 42) {
                return;
            }
            String newText = message.text + '!';
            api.editMessageText(message.chat.id, message.message_id, newText, null, true, markup);
            break;
        case ANSWER:
            api.answerCallbackQuery(callbackQuery, "This is a normal answer", false, null, 0);
            break;
        case ALERT:
            api.answerCallbackQuery(callbackQuery, "This is an alert", true, null, 0);
            break;
        case HIDE:
            api.editMessageText(message.chat.id, message.message_id, "Message without inline keyboard", null, true,
                    null); // No markup
            break;
        default:
            api.debug("Unknown command in callbackQuery: " + data);
        }
    } catch (IOException e) {
        if (api.isOwner(callbackQuery.from)) {
            api.debug(e);
        }
    }
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:35,代码来源:InlineKeyboard.java

示例7: run

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
    if (helpText == null) { // Lazy initialization
        StringBuilder builder = new StringBuilder();
        builder.append("You can use the following commands:\n");
        for (Command command : commands) {
            // "/command_name - description"
            builder.append("/").append(command.getName()).append(" - ").append(command.getDescription())
                    .append('\n');
        }
        helpText = builder.toString();
    }
    api.sendMessage(message.chat.id, helpText);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:15,代码来源:Help.java

示例8: handleMessage

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
private void handleMessage(Message message) throws IOException {
    String text = message.text;
    if (text == null) {
        // Allow commands in captions too for photos etc.
        text = message.caption;
    }

    // Find command and run it
    if (text != null && text.startsWith("/")) {
        String[] parts = text.substring(1).split(" ", 2);
        Command command = commands.get(parts[0]);
        if (command != null) {
            command.run(message);
            return;
        }
    }

    if (message.contact != null) {
        api.sendMessage(message.chat.id, message.contact.phone_number);
        return;
    }
    
    Location location = message.location;
    if (location != null) {
        api.sendLocation(message.chat.id, location.latitude, location.longitude, 0, null);
        return;
    }

    if (message.document != null) {
        api.sendMessage(message.chat.id, "File id: " + message.document.file_id);
        return;
    }
    
    // Unknown command. Show help text instead
    commands.get("help").run(message);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:37,代码来源:ExampleServlet.java

示例9: forwardMessage

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
/**
 * @see <a href="https://core.telegram.org/bots/api#forwardmessage">Official documentation of forwardMessage</a>
 */
public Message forwardMessage(long chatId, long fromChatId, int messageId) throws IOException {
    StringBuilder command = new StringBuilder(FORWARD_MESSAGE);
    command.append("chat_id=").append(chatId);
    command.append("&from_chat_id=").append(fromChatId);
    if (disableNotification) {
        command.append("&disable_notification=true");
    }
    command.append("&message_id=").append(messageId);
    return callMethod(command.toString(), Message.class);
}
 
开发者ID:nadam,项目名称:tg-bot-api,代码行数:14,代码来源:TgBotApi.java

示例10: run

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
    api.sendMessage(message.chat.id, "Keyboard hidden", null, false, 0, REPLY_KEYBOARD_HIDE);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:5,代码来源:HideKeyboard.java

示例11: run

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
    api.sendMessage(message.chat.id, "Message with inline keyboard", null, false, 0, markup);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:5,代码来源:InlineKeyboard.java

示例12: run

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
    long chatId = message.chat.id;
    api.sendLocation(chatId, 13.752725f, 100.530195f, 0, null);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:6,代码来源:Bangkok.java

示例13: run

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
    api.sendGame(message.chat.id, "dummy", 0, markup);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:5,代码来源:DummyGame.java

示例14: run

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
    api.forwardMessage(message.chat.id, message);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:5,代码来源:Forward.java

示例15: run

import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
    api.sendMessage(message.chat.id, aboutText, ParseMode.MARKDOWN, true, 0, null);
}
 
开发者ID:nadam,项目名称:tg-bot-api-example,代码行数:5,代码来源:About.java


注:本文中的se.anyro.tgbotapi.types.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。