Search in sources :

Example 6 with SendMessage

use of org.telegram.telegrambots.api.methods.send.SendMessage 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 SendMessage

use of org.telegram.telegrambots.api.methods.send.SendMessage in project webofneeds by researchstudio-sat.

the class TelegramMessageGenerator method getErrorMessage.

public SendMessage getErrorMessage(Long chatId) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.setChatId(chatId);
    sendMessage.setText("could not create need wrong syntax");
    return sendMessage;
}
Also used : SendMessage(org.telegram.telegrambots.api.methods.send.SendMessage)

Example 8 with SendMessage

use of org.telegram.telegrambots.api.methods.send.SendMessage in project webofneeds by researchstudio-sat.

the class TelegramMessageGenerator method getConnectMessage.

public SendMessage getConnectMessage(Long chatId, URI remoteNeedUri, URI yourNeedUri) {
    Dataset remoteNeedRDF = eventListenerContext.getLinkedDataSource().getDataForResource(remoteNeedUri);
    DefaultNeedModelWrapper needModelWrapper = new DefaultNeedModelWrapper(remoteNeedRDF);
    String title = needModelWrapper.getSomeTitleFromIsOrAll("en", "de");
    String description = needModelWrapper.getSomeDescription(NeedContentPropertyType.ALL, "en", "de");
    SendMessage sendMessage = new SendMessage();
    sendMessage.setChatId(chatId);
    String text = "<b>Someone wants to connect with you!\n\n</b><a href='" + remoteNeedUri + "'>" + title + "\n\n</a>";
    if (description != null) {
        text = text + "<em>" + description + "</em>";
    }
    sendMessage.setText(text);
    sendMessage.setReplyMarkup(getConnectionActionKeyboard("Accept", "Deny"));
    sendMessage.enableHtml(true);
    return sendMessage;
}
Also used : DefaultNeedModelWrapper(won.protocol.util.DefaultNeedModelWrapper) Dataset(org.apache.jena.query.Dataset) SendMessage(org.telegram.telegrambots.api.methods.send.SendMessage)

Example 9 with SendMessage

use of org.telegram.telegrambots.api.methods.send.SendMessage 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 SendMessage

use of org.telegram.telegrambots.api.methods.send.SendMessage 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

SendMessage (org.telegram.telegrambots.api.methods.send.SendMessage)11 TelegramApiException (org.telegram.telegrambots.exceptions.TelegramApiException)6 Subscribers (jenkinsci.plugins.telegrambot.users.Subscribers)3 Dataset (org.apache.jena.query.Dataset)3 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)3