Skip to content

Commit

Permalink
v1.0.0: (#27)
Browse files Browse the repository at this point in the history
Implemented all the logic, planned up to MVP:
*   User can subscribe to a group of posts
*   User can view a list of group subscriptions on which user subscribes
*   User can unsubscribe from a group of posts
*   User can set an inactive bot and do not receive notifications
*   User can restart getting notifications
*   Admin has the ability to see bot statistics
  • Loading branch information
Roman Beskrovnyi authored May 27, 2021
1 parent 14bdf10 commit 8fcb502
Show file tree
Hide file tree
Showing 44 changed files with 185 additions and 177 deletions.
39 changes: 14 additions & 25 deletions Find_New_Articles_WF.bpmn → Find_New_Posts_WF.bpmn
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0pm0ags" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.4.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_0pm0ags" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.8.1">
<bpmn:process id="Process_0q8qan7" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="Find new articles workflow started">
<bpmn:startEvent id="StartEvent_1" name="Find new Posts workflow started">
<bpmn:outgoing>Flow_0yrxqwq</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="Activity_0q4i3mw" name="Find New Article Scheduler">
<bpmn:task id="Activity_0q4i3mw" name="Find New Posts Scheduler">
<bpmn:incoming>Flow_0yrxqwq</bpmn:incoming>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_0yrxqwq" sourceRef="StartEvent_1" targetRef="Activity_0q4i3mw" />
Expand All @@ -14,7 +14,7 @@
<bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT24H</bpmn:timeDuration>
</bpmn:timerEventDefinition>
</bpmn:boundaryEvent>
<bpmn:task id="Activity_0xf7sm3" name="Find all active Group Subscriptions">
<bpmn:task id="Activity_0xf7sm3" name="Get All Groups Subscriptions">
<bpmn:incoming>Flow_150dsht</bpmn:incoming>
<bpmn:outgoing>Flow_1g56vij</bpmn:outgoing>
</bpmn:task>
Expand All @@ -24,12 +24,12 @@
<bpmn:outgoing>Flow_14geq43</bpmn:outgoing>
</bpmn:task>
<bpmn:sequenceFlow id="Flow_1g56vij" sourceRef="Activity_0xf7sm3" targetRef="Activity_1ie0g58" />
<bpmn:endEvent id="Event_1sb4kpc" name="Find new articles workflow stopped">
<bpmn:endEvent id="Event_1sb4kpc" name="Find new posts workflow stopped">
<bpmn:incoming>Flow_0lqyzo8</bpmn:incoming>
<bpmn:incoming>Flow_0xev53g</bpmn:incoming>
<bpmn:terminateEventDefinition id="TerminateEventDefinition_0b0syf0" />
</bpmn:endEvent>
<bpmn:exclusiveGateway id="Gateway_16cr3lf" name="Does group subscription has new articles?">
<bpmn:exclusiveGateway id="Gateway_16cr3lf" name="Does group subscription has new posts?">
<bpmn:incoming>Flow_14geq43</bpmn:incoming>
<bpmn:outgoing>Flow_0lqyzo8</bpmn:outgoing>
<bpmn:outgoing>Flow_0ux9vtc</bpmn:outgoing>
Expand All @@ -42,16 +42,12 @@
</bpmn:task>
<bpmn:sequenceFlow id="Flow_0ux9vtc" name="Yes" sourceRef="Gateway_16cr3lf" targetRef="Activity_1unl7hc" />
<bpmn:sequenceFlow id="Flow_0xev53g" sourceRef="Activity_1unl7hc" targetRef="Event_1sb4kpc" />
<bpmn:textAnnotation id="TextAnnotation_0ktq7fk">
<bpmn:text>Active group subscription is  subscription, which linked to active User.</bpmn:text>
</bpmn:textAnnotation>
<bpmn:association id="Association_0tv4faj" sourceRef="Activity_0xf7sm3" targetRef="TextAnnotation_0ktq7fk" />
<bpmn:textAnnotation id="TextAnnotation_0e7hzky">
<bpmn:text>Runs every 15 minutes</bpmn:text>
</bpmn:textAnnotation>
<bpmn:association id="Association_0757sxs" sourceRef="Event_1duo9io" targetRef="TextAnnotation_0e7hzky" />
<bpmn:textAnnotation id="TextAnnotation_02jhypi">
<bpmn:text>Find new articles for each group subscription since last time</bpmn:text>
<bpmn:text>Find new posts for each group subscription since last time</bpmn:text>
</bpmn:textAnnotation>
<bpmn:association id="Association_1ers88j" sourceRef="Activity_1ie0g58" targetRef="TextAnnotation_02jhypi" />
</bpmn:process>
Expand Down Expand Up @@ -97,7 +93,7 @@
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="156" y="66" width="83" height="27" />
<dc:Bounds x="158" y="66" width="80" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0q4i3mw_di" bpmnElement="Activity_0q4i3mw">
Expand All @@ -109,6 +105,12 @@
<bpmndi:BPMNShape id="Activity_1ie0g58_di" bpmnElement="Activity_1ie0g58">
<dc:Bounds x="600" y="200" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1sb4kpc_di" bpmnElement="Event_1sb4kpc">
<dc:Bounds x="1022" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="997" y="66" width="85" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_16cr3lf_di" bpmnElement="Gateway_16cr3lf" isMarkerVisible="true">
<dc:Bounds x="765" y="215" width="50" height="50" />
<bpmndi:BPMNLabel>
Expand All @@ -118,31 +120,18 @@
<bpmndi:BPMNShape id="Activity_1unl7hc_di" bpmnElement="Activity_1unl7hc">
<dc:Bounds x="890" y="200" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="TextAnnotation_0ktq7fk_di" bpmnElement="TextAnnotation_0ktq7fk">
<dc:Bounds x="430" y="99" width="230" height="40" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="TextAnnotation_0e7hzky_di" bpmnElement="TextAnnotation_0e7hzky">
<dc:Bounds x="200" y="210" width="100" height="40" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="TextAnnotation_02jhypi_di" bpmnElement="TextAnnotation_02jhypi">
<dc:Bounds x="660" y="78" width="140" height="68" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1sb4kpc_di" bpmnElement="Event_1sb4kpc">
<dc:Bounds x="1022" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="997" y="66" width="85" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1vo0kt7_di" bpmnElement="Event_1duo9io">
<dc:Bounds x="352" y="139" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="379" y="171" width="30" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Association_0tv4faj_di" bpmnElement="Association_0tv4faj">
<di:waypoint x="524" y="200" />
<di:waypoint x="575" y="139" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Association_0757sxs_di" bpmnElement="Association_0757sxs">
<di:waypoint x="354" y="166" />
<di:waypoint x="276" y="210" />
Expand Down
9 changes: 0 additions & 9 deletions HELP.md

This file was deleted.

21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@
JavaRush Telegram bot from community for community. Written by developers, who learned in [Javarush](https://javarush.ru).
## Idea
The main idea is to show how to create real application, which can be used by someone else.
There are [set of articles](https://javarush.ru/groups/posts/2935-java-proekt-ot-a-do-ja-pishem-realjhnihy-proekt-dlja-portfolio), which are describing step by step guidelines of how it was created.
There are [set of posts](https://javarush.ru/groups/posts/2935-java-proekt-ot-a-do-ja-pishem-realjhnihy-proekt-dlja-portfolio), which are describing step by step guidelines of how it was created.
## MVP Scope
As a user, I want to subscribe on group of articles and get notification via telegram-bot every time,
when new article, related to group subscriptions, has come.
As a user, I want to subscribe on group of posts and get notification via telegram-bot every time,
when new post, related to group subscriptions, has come.

# How it would work
# How it works
Based on MVP Scope, we can specify next behaviours (here and after Telegram User, which is using JavaRush Telgegram bot will call User):
- User can subscribe on group of articles
- User can view list of gorup subscriptions on which user subscribes
- User can unsubscribe from gorup of articles
- User can subscribe on group of posts
- User can view list of group subscriptions on which user subscribes
- User can unsubscribe from group of posts
- User can set an inactive bot and do not receive notifications
- User can restart getting notifications
## Find new articles workflow
The workflow of finding new articles and send them to subscribers can be viewed here:
![Find_New_Articles_WF](https://user-images.githubusercontent.com/16310793/103340221-62bb5400-4a38-11eb-947f-c28ce8ecad1b.png)

## Find new posts workflow
The workflow of finding new posts and send them to subscribers can be viewed here:
![Find_New_Posts_WF](https://user-images.githubusercontent.com/16310793/119827993-6c22ec80-bf02-11eb-8759-83bea483db93.png)
## Deployment
Deployment process as easy as possible:
Required software:
Expand Down
9 changes: 9 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Release Notes

## 1.0.0
Implemented all the logic, planned up to MVP:
* User can subscribe on group of posts
* User can view list of group subscriptions on which user subscribes
* User can unsubscribe from group of posts
* User can set an inactive bot and do not receive notifications
* User can restart getting notifications
* Admin has ability to see bot statistics

## 0.8.0-SNAPSHOT
* JRTB-10: extended bot statistics for admins.

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.github.javarushcommunity</groupId>
<artifactId>javarush-telegrambot</artifactId>
<version>0.8.0-SNAPSHOT</version>
<version>1.0.0</version>
<name>Javarush TelegramBot</name>
<description>Telegram bot for Javarush from community to community</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public void onUpdateReceived(Update update) {
String username = update.getMessage().getFrom().getUserName();
if (message.startsWith(COMMAND_PREFIX)) {
String commandIdentifier = message.split(" ")[0].toLowerCase();
commandContainer.retrieveCommand(commandIdentifier, username).execute(update);
commandContainer.findCommand(commandIdentifier, username).execute(update);
} else {
commandContainer.retrieveCommand(NO.getCommandName(), username).execute(update);
commandContainer.findCommand(NO.getCommandName(), username).execute(update);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void execute(Update update) {
return;
}
String groupId = getMessage(update).split(SPACE)[1];
String chatId = getChatId(update);
Long chatId = getChatId(update);
if (isNumeric(groupId)) {
GroupDiscussionInfo groupById = javaRushGroupClient.getGroupById(Integer.parseInt(groupId));
if (isNull(groupById.getId())) {
Expand All @@ -54,17 +54,17 @@ public void execute(Update update) {
}
}

private void sendGroupNotFound(String chatId, String groupId) {
private void sendGroupNotFound(Long chatId, String groupId) {
String groupNotFoundMessage = "Нет группы с ID = \"%s\"";
sendBotMessageService.sendMessage(chatId, String.format(groupNotFoundMessage, groupId));
}

private void sendNotValidGroupID(String chatId, String groupId) {
private void sendNotValidGroupID(Long chatId, String groupId) {
String groupNotFoundMessage = "Неправильный ID группы = \"%s\"";
sendBotMessageService.sendMessage(chatId, String.format(groupNotFoundMessage, groupId));
; }

private void sendGroupIdList(String chatId) {
private void sendGroupIdList(Long chatId) {
String groupIds = javaRushGroupClient.getGroupList(GroupRequestArgs.builder().build()).stream()
.map(group -> String.format("%s - %s \n", group.getTitle(), group.getId()))
.collect(Collectors.joining());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.telegram.telegrambots.meta.api.objects.Update;

import static com.github.javarushcommunity.jrtb.command.CommandName.STAT;
import static com.github.javarushcommunity.jrtb.command.CommandUtils.getChatId;
import static java.lang.String.format;

/**
Expand All @@ -24,6 +25,6 @@ public AdminHelpCommand(SendBotMessageService sendBotMessageService) {

@Override
public void execute(Update update) {
sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), ADMIN_HELP_MESSAGE);
sendBotMessageService.sendMessage(getChatId(update), ADMIN_HELP_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CommandContainer(SendBotMessageService sendBotMessageService, TelegramUse
unknownCommand = new UnknownCommand(sendBotMessageService);
}

public Command retrieveCommand(String commandIdentifier, String username) {
public Command findCommand(String commandIdentifier, String username) {
Command orDefault = commandMap.getOrDefault(commandIdentifier, unknownCommand);
if (isAdminCommand(orDefault)) {
if (admins.contains(username)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
public class CommandUtils {

/**
* Retrieve chatId from {@link Update} object.
* Get chatId from {@link Update} object.
*
* @param update provided {@link Update}
* @return chatID from the provided {@link Update} object.
*/
public static String getChatId(Update update) {
return update.getMessage().getChatId().toString();
public static Long getChatId(Update update) {
return update.getMessage().getChatId();
}

/**
* Retrieve text of the message from {@link Update} object.
* Get text of the message from {@link Update} object.
*
* @param update provided {@link Update}
* @return the text of the message from the provided {@link Update} object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void execute(Update update) {
return;
}
String groupId = getMessage(update).split(SPACE)[1];
String chatId = getChatId(update);
Long chatId = getChatId(update);
if (isNumeric(groupId)) {
Optional<GroupSub> optionalGroupSub = groupSubService.findById(Integer.valueOf(groupId));
if (optionalGroupSub.isPresent()) {
Expand All @@ -61,7 +61,7 @@ public void execute(Update update) {
}
}

private void sendGroupIdList(String chatId) {
private void sendGroupIdList(Long chatId) {
String message;
List<GroupSub> groupSubs = telegramUserService.findByChatId(chatId)
.orElseThrow(NotFoundException::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.telegram.telegrambots.meta.api.objects.Update;

import static com.github.javarushcommunity.jrtb.command.CommandName.*;
import static com.github.javarushcommunity.jrtb.command.CommandUtils.getChatId;

/**
* Help {@link Command}.
Expand Down Expand Up @@ -33,6 +34,6 @@ public HelpCommand(SendBotMessageService sendBotMessageService) {

@Override
public void execute(Update update) {
sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), HELP_MESSAGE);
sendBotMessageService.sendMessage(getChatId(update), HELP_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.github.javarushcommunity.jrtb.service.SendBotMessageService;
import org.telegram.telegrambots.meta.api.objects.Update;

import static com.github.javarushcommunity.jrtb.command.CommandUtils.getChatId;

/**
* No {@link Command}.
*/
Expand All @@ -19,6 +21,6 @@ public NoCommand(SendBotMessageService sendBotMessageService) {

@Override
public void execute(Update update) {
sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), NO_MESSAGE);
sendBotMessageService.sendMessage(getChatId(update), NO_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.github.javarushcommunity.jrtb.service.TelegramUserService;
import org.telegram.telegrambots.meta.api.objects.Update;

import static com.github.javarushcommunity.jrtb.command.CommandUtils.getChatId;

/**
* Start {@link Command}.
*/
Expand All @@ -25,7 +27,7 @@ public StartCommand(SendBotMessageService sendBotMessageService, TelegramUserSer

@Override
public void execute(Update update) {
String chatId = update.getMessage().getChatId().toString();
Long chatId = getChatId(update);

telegramUserService.findByChatId(chatId).ifPresentOrElse(
user -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import java.util.stream.Collectors;

import static com.github.javarushcommunity.jrtb.command.CommandUtils.getChatId;

/**
* Statistics {@link Command}.
*/
Expand Down Expand Up @@ -39,7 +41,7 @@ public void execute(Update update) {
.map(it -> String.format("%s (id = %s) - %s подписчиков", it.getTitle(), it.getId(), it.getActiveUserCount()))
.collect(Collectors.joining("\n"));

sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), String.format(STAT_MESSAGE,
sendBotMessageService.sendMessage(getChatId(update), String.format(STAT_MESSAGE,
statisticDTO.getActiveUserCount(),
statisticDTO.getInactiveUserCount(),
statisticDTO.getAverageGroupCountByUser(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.util.Optional;

import static com.github.javarushcommunity.jrtb.command.CommandUtils.getChatId;

/**
* Stop {@link Command}.
*/
Expand All @@ -25,8 +27,8 @@ public StopCommand(SendBotMessageService sendBotMessageService, TelegramUserServ

@Override
public void execute(Update update) {
sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), STOP_MESSAGE);
telegramUserService.findByChatId(update.getMessage().getChatId().toString())
sendBotMessageService.sendMessage(getChatId(update), STOP_MESSAGE);
telegramUserService.findByChatId(getChatId(update))
.ifPresent(it -> {
it.setActive(false);
telegramUserService.save(it);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.github.javarushcommunity.jrtb.service.SendBotMessageService;
import org.telegram.telegrambots.meta.api.objects.Update;

import static com.github.javarushcommunity.jrtb.command.CommandUtils.getChatId;

/**
* Unknown {@link Command}.
*/
Expand All @@ -18,6 +20,6 @@ public UnknownCommand(SendBotMessageService sendBotMessageService) {

@Override
public void execute(Update update) {
sendBotMessageService.sendMessage(update.getMessage().getChatId().toString(), UNKNOWN_MESSAGE);
sendBotMessageService.sendMessage(getChatId(update), UNKNOWN_MESSAGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ public interface JavaRushGroupClient {
*/
GroupDiscussionInfo getGroupById(Integer id);

Integer findLastArticleId(Integer groupSub);
Integer findLastPostId(Integer groupSub);
}
Loading

0 comments on commit 8fcb502

Please sign in to comment.