-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JRTB-2: added stub telegram bot ti the project
- Loading branch information
Showing
5 changed files
with
59 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
...ambot/JavarushTelegrambotApplication.java → ...t/bot/JavarushTelegrambotApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/github/JBolivarLi/javarushtelegrambot/bot/bot/JavarushTelegramBot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.JBolivarLi.javarushtelegrambot.bot.bot; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.telegram.telegrambots.bots.TelegramLongPollingBot; | ||
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; | ||
import org.telegram.telegrambots.meta.api.objects.Update; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; | ||
|
||
@Component | ||
public class JavarushTelegramBot extends TelegramLongPollingBot { | ||
@Value("${bot.username}") | ||
private String username; | ||
|
||
@Value("${bot.token}") | ||
private String token; | ||
|
||
public String getBotUsername() { | ||
return username; | ||
} | ||
|
||
public String getBotToken() { | ||
return token; | ||
} | ||
|
||
public void onUpdateReceived(Update update) { | ||
if(update.hasMessage() && update.getMessage().hasText()) { | ||
String message = update.getMessage().getText().trim(); | ||
String chatId = update.getMessage().getChatId().toString(); | ||
|
||
SendMessage sm = new SendMessage(); | ||
sm.setChatId(chatId); | ||
sm.setText(message + "\n" + "fromBolivarBotWithLove"); | ||
|
||
try { | ||
execute(sm); | ||
} catch (TelegramApiException e) { | ||
//todo add logging to the project. | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
|
||
bot.username=TestJBolivarBot | ||
bot.token=6907574172:AAH_1pY6v_koa6K77p6GdRa6XT7ph7IRDBY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters