Register MessageHandler
This commit is contained in:
parent
019b1f2211
commit
3866c20cea
|
@ -1,7 +1,11 @@
|
||||||
package com.myoa.engineering.music.soundhoundfound.receiver;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
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
|
* ReceiverApplication
|
||||||
|
@ -14,5 +18,11 @@ public class ReceiverApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ReceiverApplication.class, args);
|
SpringApplication.run(ReceiverApplication.class, args);
|
||||||
|
try {
|
||||||
|
TelegramBotsApi api = new TelegramBotsApi(DefaultBotSession.class);
|
||||||
|
api.registerBot(new MessageHandler());
|
||||||
|
} catch(TelegramApiException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue