Skip to content

Commit

Permalink
JRTB-2: added stub telegram bot ti the project
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanLiVa committed Nov 15, 2023
1 parent 1bb6b84 commit 4b28b9d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
Expand All @@ -21,6 +21,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-spring-boot-starter</artifactId>
<version>6.8.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -38,4 +43,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.github.JBolivarLi.javarushtelegrambot;
package com.github.JBolivarLi.javarushtelegrambot.bot;

import com.github.JBolivarLi.javarushtelegrambot.bot.bot.JavarushTelegramBot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;



@SpringBootApplication

public class JavarushTelegrambotApplication {

public static void main(String[] args) {
Expand Down
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();
}
}

}
}
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

bot.username=TestJBolivarBot
bot.token=6907574172:AAH_1pY6v_koa6K77p6GdRa6XT7ph7IRDBY
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
//@SpringBootTest/
class JavarushTelegrambotApplicationTests {

@Test
Expand Down

0 comments on commit 4b28b9d

Please sign in to comment.