本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例14: run
import se.anyro.tgbotapi.types.Message; //导入依赖的package包/类
@Override
public void run(Message message) throws IOException {
api.forwardMessage(message.chat.id, message);
}
示例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);
}