本文整理汇总了Java中se.anyro.tgbotapi.types.Update类的典型用法代码示例。如果您正苦于以下问题:Java Update类的具体用法?Java Update怎么用?Java Update使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Update类属于se.anyro.tgbotapi.types包,在下文中一共展示了Update类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doPost
import se.anyro.tgbotapi.types.Update; //导入依赖的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);
}
}
示例2: doPost
import se.anyro.tgbotapi.types.Update; //导入依赖的package包/类
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setStatus(HttpServletResponse.SC_OK);
Update update = api.parseFromWebhook(req.getReader());
try {
if (update.isMessage()) {
handleMessage(update.message);
} else if (update.isInlineQuery()) {
inlineQueryHandler.handleInlineQuery(update.inline_query);
} else if (update.isChosenInlineResult()) {
inlineQueryHandler.handleChosenInlineResult(update.chosen_inline_result);
} else if (update.isCallbackQuery()) {
if (update.callback_query.game_short_name != null) {
game.handleCallbackQuery(update.callback_query);
} else {
inlineKeyboard.handleCallbackQuery(update.callback_query);
}
} else {
api.debug("Unexpected update");
}
} catch (Exception e) {
// Simplify testing for the owner of the bot
if (update.fromUserId() == OWNER) {
api.debug(e);
}
}
}
示例3: parseFromWebhook
import se.anyro.tgbotapi.types.Update; //导入依赖的package包/类
/**
* Parse the input in the webhook into a pojo of the json data received.
*/
public Update parseFromWebhook(String json) {
return GSON.fromJson(json, Update.class);
}
示例4: getUpdates
import se.anyro.tgbotapi.types.Update; //导入依赖的package包/类
/**
* Use this method to receive incoming updates using long polling. An Array of Update objects is returned.
*
* Only use this method if you don't use a webhook.
*
* @see <a href="https://core.telegram.org/bots/api#getupdates">Official documentation of getUpdate</a>
*/
public Update[] getUpdates(int offset, int limit, int timeout) throws IOException {
return callMethod(GET_UPDATES + "offset=" + offset + "&limit=" + limit + "&timeout=" + timeout, Update[].class);
}