Skip to content

Commit

Permalink
added notification service and telegram bot
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegStashkiv committed Oct 3, 2023
1 parent 3275e6d commit f94a0d1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Data
@Configuration
@PropertySource("application.properties")
public class TelegramBotConfig {
@Value("${bot.name}")
private String botName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class NotificationService extends TelegramLongPollingBot {
private final TelegramBotConfig config;
private final UserRepository userRepository;

@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasText()) {
Expand All @@ -25,6 +26,8 @@ public void onUpdateReceived(Update update) {
case "/start":
startCommandReceived(chatId, update.getMessage().getChat().getFirstName());
break;
default:
break;
}
if (!messageText.startsWith("/")) {
saveUserChatId(chatId, update.getMessage().getText());
Expand Down Expand Up @@ -61,9 +64,9 @@ public void sendNotification(Long userId, String message) {
}

private void startCommandReceived(Long chatId, String firstName) {
String answer = "Hi, " + firstName + ", nice to meet you! \n"
String answer = "Hi, " + firstName + ", nice to meet you! \n"
+ "Enter your username to get started:";
sendMessage(chatId, answer);
sendMessage(chatId, answer);

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring.datasource.url=jdbc:mysql://localhost:3306/car_sharing_db?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root123
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

server.servlet.context-path=/api
Expand All @@ -9,4 +9,4 @@ spring.jpa.show-sql=true
spring.jpa.open-in-view=false

bot.name=SharingCarBot
bot.token=6631383610:AAExM59fyeZyshmxsmupqUrAV9TcitH30vk
bot.token=6631383610:AAExM59fyeZyshmxsmupqUrAV9TcitH30vk
3 changes: 3 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

bot.name=SharingCarBot
bot.token=6631383610:AAExM59fyeZyshmxsmupqUrAV9TcitH30vk

0 comments on commit f94a0d1

Please sign in to comment.