use of org.telegram.telegrambots.exceptions.TelegramApiException in project telegram-notifications-plugin by jenkinsci.
the class UnsubCommand method execute.
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {
Subscribers subscribers = Subscribers.getInstance();
String ans;
Long id = chat.getId();
boolean isSubscribed = subscribers.isSubscribed(id);
if (isSubscribed) {
subscribers.unsubscribe(id);
ans = botStrings.get("message.unsub.success");
} else {
ans = botStrings.get("message.unsub.alreadyunsub");
}
SendMessage answer = new SendMessage();
answer.setChatId(chat.getId().toString());
answer.setText(ans);
try {
absSender.execute(answer);
} catch (TelegramApiException e) {
BotLogger.error(LOG_TAG, e);
}
}
use of org.telegram.telegrambots.exceptions.TelegramApiException in project webofneeds by researchstudio-sat.
the class Hint2TelegramAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof HintFromMatcherEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
Match match = ((HintFromMatcherEvent) event).getMatch();
WonMessage wonMessage = ((HintFromMatcherEvent) event).getWonMessage();
URI yourNeedUri = match.getFromNeed();
URI remoteNeedUri = match.getToNeed();
Long chatId = botContextWrapper.getChatIdForURI(yourNeedUri);
if (chatId == null) {
logger.error("No chatId found for the specified needUri");
return;
}
try {
Message message = wonTelegramBotHandler.sendMessage(wonTelegramBotHandler.getTelegramMessageGenerator().getHintMessage(chatId, remoteNeedUri, yourNeedUri));
botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(wonMessage.getReceiverURI(), UriType.CONNECTION));
} catch (TelegramApiException te) {
logger.error(te.getMessage());
}
}
}
use of org.telegram.telegrambots.exceptions.TelegramApiException in project webofneeds by researchstudio-sat.
the class Message2TelegramAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof MessageFromOtherNeedEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
Connection con = ((MessageFromOtherNeedEvent) event).getCon();
WonMessage wonMessage = ((MessageFromOtherNeedEvent) event).getWonMessage();
URI yourNeedUri = con.getNeedURI();
URI remoteNeedUri = con.getRemoteNeedURI();
Long chatId = botContextWrapper.getChatIdForURI(yourNeedUri);
if (chatId == null) {
logger.error("No chatId found for the specified needUri");
return;
}
try {
Message message = wonTelegramBotHandler.sendMessage(wonTelegramBotHandler.getTelegramMessageGenerator().getConnectionTextMessage(chatId, remoteNeedUri, yourNeedUri, wonMessage));
botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(con.getConnectionURI(), UriType.CONNECTION));
} catch (TelegramApiException te) {
logger.error(te.getMessage());
}
}
}
use of org.telegram.telegrambots.exceptions.TelegramApiException in project telegram-notifications-plugin by jenkinsci.
the class TelegramBot method sendMessage.
public void sendMessage(Long chatId, String message) {
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(chatId.toString());
sendMessageRequest.setText(message);
sendMessageRequest.enableMarkdown(true);
try {
execute(sendMessageRequest);
} catch (TelegramApiException e) {
LOGGER.log(Level.SEVERE, String.format("TelegramBot: Error while sending message: %s%n%s", chatId, message), e);
}
}
use of org.telegram.telegrambots.exceptions.TelegramApiException in project telegram-notifications-plugin by jenkinsci.
the class HelpCommand method execute.
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {
SendMessage answer = new SendMessage();
answer.setChatId(chat.getId().toString());
answer.setText(botStrings.get("message.help"));
try {
absSender.execute(answer);
} catch (TelegramApiException e) {
BotLogger.error(LOG_TAG, e);
}
}
Aggregations