diff --git a/receiver/src/main/java/com/myoa/engineering/music/soundhoundfound/receiver/ReceiverApplication.java b/receiver/src/main/java/com/myoa/engineering/music/soundhoundfound/receiver/ReceiverApplication.java index f7c1610..5c49c76 100644 --- a/receiver/src/main/java/com/myoa/engineering/music/soundhoundfound/receiver/ReceiverApplication.java +++ b/receiver/src/main/java/com/myoa/engineering/music/soundhoundfound/receiver/ReceiverApplication.java @@ -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(); + } } } diff --git a/receiver/src/main/java/com/myoa/engineering/music/soundhoundfound/receiver/dispatch/MessageHandler.java b/receiver/src/main/java/com/myoa/engineering/music/soundhoundfound/receiver/dispatch/MessageHandler.java new file mode 100644 index 0000000..a978f85 --- /dev/null +++ b/receiver/src/main/java/com/myoa/engineering/music/soundhoundfound/receiver/dispatch/MessageHandler.java @@ -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; + } +}