Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public TelegramBot(String token, String name) {
new HelpCommand(),
new SubCommand(),
new UnsubCommand(),
new StatusCommand()
new StatusCommand(),
new ChatidCommand()
).forEach(this::register);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package jenkinsci.plugins.telegrambot.telegram.commands;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

public class ChatidCommand extends AbstractBotCommand {

private static final String LOG_TAG = "/chatid";
private static final Logger LOGGER = LoggerFactory.getLogger(ChatidCommand.class);

public ChatidCommand() {
super("chatid", "command.chatid");
}

@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {
SendMessage answer = new SendMessage();
answer.setChatId(chat.getId().toString());
answer.setText(chat.getId().toString());

try {
absSender.execute(answer);
} catch (TelegramApiException e) {
LOGGER.error(LOG_TAG, e);
}
}
}

3 changes: 2 additions & 1 deletion src/main/resources/bot.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ message.help=You're using Jenkins Bot. It can send to you some Jenkins messages.
\/help - display this message\n\
\/sub - subscribe for Jenkins messages\n\
\/unsub - unsubscribe from Jenkins messages\n\
\/status - get your status
\/status - get your status\n\
\/chatid - get your Telegram chat ID

message.status.approved=You've subscribed and approved for Jenkins messages.
message.status.unapproved=You've subscribed but not approved for Jenkins messages.
Expand Down