本文整理汇总了Java中com.pengrad.telegrambot.TelegramBot.execute方法的典型用法代码示例。如果您正苦于以下问题:Java TelegramBot.execute方法的具体用法?Java TelegramBot.execute怎么用?Java TelegramBot.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pengrad.telegrambot.TelegramBot
的用法示例。
在下文中一共展示了TelegramBot.execute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executarBot
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
/**
* Executa a inicializa��o do bot e realiza o 'polling' de mensagens enviadas
*/
public void executarBot() {
TelegramBot bot = TelegramBotAdapter.build(TOKEN_ACESSO);
int m = 0;
while (true) {
List<Update> updates = bot.execute(new GetUpdates().limit(100).offset(m)).updates();
for (Update update : updates) {
m = update.updateId() + 1;
String mensagemRetorno = "";
if (update.message() != null) {
bot.execute(new SendChatAction(update.message().chat().id(), ChatAction.typing.name()));
try {
mensagemRetorno = tratarMensagemBot(update);
} catch (Exception e) {
mensagemRetorno = "Desculpe, n�o entendi... digite /ajuda para obter a lista de comandos conhecidos.";
}
bot.execute(new SendMessage(update.message().chat().id(), mensagemRetorno.toString()));
}
}
}
}
示例2: apply
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
@Override
public void apply(final SendMessage sendMessage) {
final ImageSendPayload imageSendPayload = sendMessage.getPayloadWithType(ImageSendPayload.class);
final String title = imageSendPayload.getTitle();
final String imageUrl = imageSendPayload.getImageUrl();
final String recipient = sendMessage.getRecipient().getId();
final SendPhoto sendPhotoTelegram = new SendPhoto(recipient, imageUrl);
if (!Strings.isBlank(title)) {
sendPhotoTelegram.caption(title);
}
LOG.info("sending image {} to recipient {}", sendPhotoTelegram, recipient);
final TelegramBot client = provideTelegramBot(sendMessage);
client.execute(sendPhotoTelegram);
}
示例3: apply
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
@Override
public void apply(final SendMessage sendMessage) {
final VideoSendPayload videoSendPayload = sendMessage.getPayloadWithType(VideoSendPayload.class);
final String title = videoSendPayload.getTitle();
final String videoUrl = videoSendPayload.getVideoUrl();
final String recipient = sendMessage.getRecipient().getId();
final SendVideo sendVideoTelegram = new SendVideo(recipient, videoUrl);
if (!Strings.isBlank(title)) {
sendVideoTelegram.caption(title);
}
LOG.info("sending video {} to recipient {}", sendVideoTelegram, recipient);
final TelegramBot client = provideTelegramBot(sendMessage);
client.execute(sendVideoTelegram);
}
示例4: init
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
@Inject
protected void init() {
final String webhookUrl = telegramConfigService.getWebhookUrl((ReceiveMessage) null);
if (Strings.isBlank(webhookUrl)) {
} else {
final SetWebhook request = new SetWebhook().url(webhookUrl);
final TelegramBot bot = provideTelegramBot();
bot.execute(request);
}
}
示例5: getFileUrl
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
protected String getFileUrl(final ReceiveMessage receiveMessage, final String fileId) {
final TelegramBot bot = provideTelegramBot(receiveMessage);
final GetFile getFile = new GetFile(fileId);
final GetFileResponse response = bot.execute(getFile);
final File file = response.file();
final String url = bot.getFullFilePath(file);
return url;
}
示例6: sendPhotoElement
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
protected void sendPhotoElement(final SendMessage sendMessage, final String recipient,
final ListSendElement listSendElement) {
final SendPhoto sendPhotoTelegram = new SendPhoto(recipient, listSendElement.getImageUrl());
final String title = listSendElement.getTitle();
if (!Strings.isBlank(title)) {
sendPhotoTelegram.caption(title);
}
LOG.info("sending image {} to recipient {}", sendPhotoTelegram, recipient);
final TelegramBot client = provideTelegramBot(sendMessage);
client.execute(sendPhotoTelegram);
}
示例7: requestDescription
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
@Nullable
public BotInfo requestDescription(@NotNull TelegramSettings settings) {
TelegramBot bot = createBot(settings);
GetMeResponse response = bot.execute(new GetMe());
User user = response.user();
if (user == null) {
return null;
}
return new BotInfo(user.firstName(), user.username());
}
示例8: apply
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
@Override
public void apply(final SendMessage sendMessage) {
final BaseRequest message = (BaseRequest) sendMessage.getNativePayload(TelegramPlatformEnum.TELEGRAM);
final TelegramBot client = provideTelegramBot(sendMessage);
client.execute(message);
}
示例9: execute
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
protected void execute(final SendMessage sendMessage, final com.pengrad.telegrambot.request.SendMessage message,
final String recipient) {
LOG.info("sending to {} message {}", recipient, message);
final TelegramBot client = provideTelegramBot(sendMessage);
client.execute(message);
}
示例10: sendNotification
import com.pengrad.telegrambot.TelegramBot; //导入方法依赖的package包/类
public void sendNotification(@NotNull Notification notification) {
final StringBuilder message = new StringBuilder();
String imContent = notification.getIMContent();
if (!StringUtils.isEmpty(imContent) && resultsSummary != null) {
if (resultsSummary.isSuccessful()) {
message.append("\uD83D\uDE00 \uD83D\uDC4C ");
} else {
message.append("\uD83D\uDE31 \uD83D\uDE45\u200D♂️ ");
}
message.append(imContent).append(resultsSummary.getReasonSummary()).append("\n");
List<String> authorsNames = resultsSummary.getUniqueAuthors().stream().map(Author::getFullName).collect(Collectors.toList());
if (!authorsNames.isEmpty()) {
message.append(" Responsible Users: ")
.append(String.join(", ", authorsNames))
.append("\n");
}
List<VariableSubstitution> variables = resultsSummary.getManuallyOverriddenVariables();
if (!variables.isEmpty()) {
message.append("Variables: \n");
for (VariableSubstitution variable : variables) {
message.append(variable.getKey())
.append(": ")
.append(variable.getKey().contains("password") ? "******" :variable.getValue())
.append(" \n");
}
}
List<String> labels = resultsSummary.getLabelNames();
if (!labels.isEmpty()) {
message.append("Labels: ")
.append(String.join(", ", labels))
.append("\n");
}
Set<LinkedJiraIssue> jiraIssues = resultsSummary.getRelatedJiraIssues();
if (!jiraIssues.isEmpty()) {
message.append("Issues: \n");
for (LinkedJiraIssue issue : jiraIssues) {
if (issue.getJiraIssueDetails() == null) {
message.append(issue.getIssueKey());
} else {
message.append("<a href=\"")
.append(issue.getJiraIssueDetails().getDisplayUrl())
.append("\">")
.append(issue.getIssueKey())
.append("</a>")
.append(" - ")
.append(issue.getJiraIssueDetails().getSummary());
}
message.append("\n");
}
}
}
try {
TelegramBot bot = TelegramBotAdapter.build(botToken);
SendMessage request = new SendMessage(chatId, message.toString())
.parseMode(ParseMode.HTML);
BaseResponse response = bot.execute(request);
if (!response.isOk()) {
log.error("Error using telegram API. error code: " + response.errorCode() + " message: " + response.description());
} else {
log.info("Success Telegram API message response: " + response.description() + " toString: " + response.toString());
}
} catch (RuntimeException e) {
log.error("Error using telegram API: " + e.getMessage(), e);
}
}