Register MessageHandler

This commit is contained in:
woo-jin.shin 2021-08-20 18:40:45 +09:00
parent 019b1f2211
commit 3866c20cea
2 changed files with 39 additions and 0 deletions

View File

@ -1,7 +1,11 @@
package com.myoa.engineering.music.soundhoundfound.receiver;
import com.myoa.engineering.music.soundhoundfound.receiver.dispatch.MessageHandler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
/**
* ReceiverApplication
@ -14,5 +18,11 @@ public class ReceiverApplication {
public static void main(String[] args) {
SpringApplication.run(ReceiverApplication.class, args);
try {
TelegramBotsApi api = new TelegramBotsApi(DefaultBotSession.class);
api.registerBot(new MessageHandler());
} catch(TelegramApiException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,29 @@
package com.myoa.engineering.music.soundhoundfound.receiver.dispatch;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
@Slf4j
public class MessageHandler extends TelegramLongPollingBot {
private static final String BOT_TOKEN = "bottoken";
private static final String BOT_NAME = "nthfuncx_SoundHoundFoundBot";
@Override
public String getBotToken() {
return BOT_TOKEN;
}
@Override
public void onUpdateReceived(Update update) {
Message message = update.getMessage();
log.info(message.getText());
}
@Override
public String getBotUsername() {
return BOT_NAME;
}
}