|
|
@@ -4,53 +4,49 @@ import com.izouma.awesomeAdmin.service.TelegramBotConfig;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.telegram.telegrambots.bots.TelegramLongPollingBot;
|
|
|
-import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
|
|
|
-import org.telegram.telegrambots.meta.api.objects.Chat;
|
|
|
-import org.telegram.telegrambots.meta.api.objects.MessageEntity;
|
|
|
+import org.telegram.abilitybots.api.bot.AbilityBot;
|
|
|
+import org.telegram.abilitybots.api.objects.Ability;
|
|
|
+import org.telegram.abilitybots.api.objects.Locality;
|
|
|
+import org.telegram.abilitybots.api.objects.Privacy;
|
|
|
import org.telegram.telegrambots.meta.api.objects.Update;
|
|
|
-import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
|
|
|
@EnableConfigurationProperties(TelegramBotConfig.class)
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
-public class TelegramBot extends TelegramLongPollingBot {
|
|
|
+public class TelegramBot extends AbilityBot {
|
|
|
|
|
|
private final TelegramBotConfig config;
|
|
|
|
|
|
public TelegramBot(TelegramBotConfig config) {
|
|
|
- super(config.getToken());
|
|
|
+ super(config.getToken(), config.getUsername());
|
|
|
this.config = config;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onUpdateReceived(Update update) {
|
|
|
- if (update.hasMessage() && update.getMessage().hasText()) {
|
|
|
- String text = update.getMessage().getText();
|
|
|
- log.info("Received message: {}", text);
|
|
|
- Chat chat = update.getMessage().getChat();
|
|
|
- log.info("Chat: id={} type={} title={}", chat.getId(), chat.getType(), chat.getTitle());
|
|
|
- if (update.getMessage().getEntities() != null) {
|
|
|
- for (MessageEntity entity : update.getMessage().getEntities()) {
|
|
|
- log.info("Entity: type={} text={}", entity.getType(), entity.getText());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
|
|
|
- message.setChatId(update.getMessage().getChatId().toString());
|
|
|
- message.setText("hello");
|
|
|
-
|
|
|
- try {
|
|
|
- execute(message); // Call method to send the message
|
|
|
- } catch (TelegramApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+ public long creatorId() {
|
|
|
+ return config.getCreatorId();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String getBotUsername() {
|
|
|
- return config.getUsername();
|
|
|
+ public void onUpdatesReceived(List<Update> updates) {
|
|
|
+ super.onUpdatesReceived(updates);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onClosing() {
|
|
|
+ super.onClosing();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Ability sayHelloWorld() {
|
|
|
+ return Ability
|
|
|
+ .builder()
|
|
|
+ .name("hello")
|
|
|
+ .info("says hello world!")
|
|
|
+ .locality(Locality.ALL)
|
|
|
+ .privacy(Privacy.PUBLIC)
|
|
|
+ .action(ctx -> silent.send("Hello world!", ctx.chatId()))
|
|
|
+ .build();
|
|
|
+ }
|
|
|
}
|