Search in sources :

Example 6 with TelegramApiException

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);
    }
}
Also used : TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) Subscribers(jenkinsci.plugins.telegrambot.users.Subscribers) SendMessage(org.telegram.telegrambots.api.methods.send.SendMessage)

Example 7 with TelegramApiException

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());
        }
    }
}
Also used : TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) TelegramBotContextWrapper(won.bot.framework.bot.context.TelegramBotContextWrapper) Message(org.telegram.telegrambots.api.objects.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI) Match(won.protocol.model.Match)

Example 8 with TelegramApiException

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());
        }
    }
}
Also used : TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) MessageFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherNeedEvent) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) TelegramBotContextWrapper(won.bot.framework.bot.context.TelegramBotContextWrapper) Message(org.telegram.telegrambots.api.objects.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI)

Example 9 with TelegramApiException

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);
    }
}
Also used : TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) SendMessage(org.telegram.telegrambots.api.methods.send.SendMessage)

Example 10 with TelegramApiException

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);
    }
}
Also used : TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) SendMessage(org.telegram.telegrambots.api.methods.send.SendMessage)

Aggregations

TelegramApiException (org.telegram.telegrambots.exceptions.TelegramApiException)11 SendMessage (org.telegram.telegrambots.api.methods.send.SendMessage)6 URI (java.net.URI)4 Message (org.telegram.telegrambots.api.objects.Message)4 TelegramBotContextWrapper (won.bot.framework.bot.context.TelegramBotContextWrapper)4 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)4 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)4 Subscribers (jenkinsci.plugins.telegrambot.users.Subscribers)3 WonMessage (won.protocol.message.WonMessage)3 Connection (won.protocol.model.Connection)2 InvalidParameterException (java.security.InvalidParameterException)1 Dataset (org.apache.jena.query.Dataset)1 BotSession (org.telegram.telegrambots.generics.BotSession)1 Event (won.bot.framework.eventbot.event.Event)1 TelegramCreateNeedEvent (won.bot.framework.eventbot.event.impl.telegram.TelegramCreateNeedEvent)1 ConnectFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent)1 FailureResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)1 HintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent)1 MessageFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherNeedEvent)1 EventListener (won.bot.framework.eventbot.listener.EventListener)1