Skip to content

Commit 17f6461

Browse files
authored
Merge pull request #85 from tanhongit/multiple-bot
Docs: update flowchart and add code flow for send notification
2 parents 69b7573 + 88b8204 commit 17f6461

File tree

1 file changed

+63
-17
lines changed

1 file changed

+63
-17
lines changed

docs/send-notification-flow.md

+63-17
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ The git repository sends a webhook to the bot if any event occurs. The webhook c
1717
### The bot processes the webhook message
1818

1919
When an application receives a webhook message from the git repository, the bot processes the webhook message.
20-
It checks if the webhook is set or not. If the event has any actions and the event is allowed notify in the settings, etc.
20+
It checks if the webhook is set or not. If the event has any actions and the event is allowed notify in the settings,
21+
etc.
2122

2223
### The bot gets the message details if the event is valid
2324

24-
If the event/action is valid, the bot will get the message details of this event/action and set the message details to the message
25+
If the event/action is valid, the bot will get the message details of this event/action and set the message details to
26+
the message
2527
object.
2628

2729
### The bot sends a notification
@@ -49,11 +51,11 @@ the `telegram-git-notifier` functionality, including configuration and views for
4951

5052
## Entity Relationship Diagram
5153

52-
5354
> [!NOTE]
5455
> The following diagram is a simplified version of the entity relationship diagram for the Telegram Git Notifier.
55-
>
56-
> The data is **still saved in JSON format**. I don't use database storage because I don't want to **affect any data on your real system**. Its purpose is only to clarify the feature's operating model.
56+
>
57+
> The data is **still saved in JSON format**. I don't use database storage because I don't want to **affect any data on
58+
your real system**. Its purpose is only to clarify the feature's operating model.
5759

5860
```mermaid
5961
erDiagram
@@ -128,7 +130,7 @@ flowchart TD
128130
subgraph "User and Repository Interaction"
129131
webhook --> user[User]
130132
user --> addWebhookToRepo[Add webhook to repository]
131-
addWebhookToRepo --> repository[Repository]
133+
addWebhookToRepo --> repository[Git Repository]
132134
user --> ownsRepo[Owns]
133135
ownsRepo --> repository
134136
end
@@ -137,13 +139,27 @@ flowchart TD
137139
triggerEvent --> sendPayload[Send event payload to bot]
138140
sendPayload --> bot
139141
140-
subgraph "Event Processing"
141-
bot --> processEvent{Process event}
142-
processEvent --> checkAction{Is there an action?}
143-
checkAction -->|Yes| actionMessage[Event type: Action]
144-
checkAction -->|No| eventNameMessage[Event type: Event name]
145-
eventNameMessage --> checkSettings{Is event allowed in settings?}
146-
actionMessage --> checkSettings
142+
subgraph "Bot Processing"
143+
bot --> detectPlatform{Detect platform}
144+
145+
subgraph "Platform Detection"
146+
detectPlatform -->|GitHub| setGithubPlatform[Set GitHub platform]
147+
detectPlatform -->|GitLab| setGitlabPlatform[Set GitLab platform]
148+
setGithubPlatform --> getGithubPlatformFile[Get GitHub platform file]
149+
setGitlabPlatform --> getGitlabPlatformFile[Get GitLab platform file]
150+
end
151+
152+
getGithubPlatformFile --> setEventConfig[Set event config]
153+
getGitlabPlatformFile --> setEventConfig[Set event config]
154+
setEventConfig --> processEvent{Process event}
155+
156+
subgraph "Event Processing"
157+
processEvent --> checkAction{Is there an action?}
158+
checkAction -->|Yes| actionMessage[event_type: Action of event]
159+
checkAction -->|No| eventNameMessage[event_type: Event name]
160+
eventNameMessage --> checkSettings{Is event_type allowed in settings?}
161+
actionMessage --> checkSettings
162+
end
147163
end
148164
149165
checkSettings -->|Yes| findTemplate{Find message template}
@@ -158,7 +174,37 @@ flowchart TD
158174
log --> endFlow
159175
```
160176

161-
## Future Work
162-
163-
In the future, additional flows will be implemented to handle other aspects of the bot's functionality, such as error
164-
handling, customizing notifications, and sending notifications to multiple users.
177+
## Code flow
178+
179+
Here is the code flow of the Telegram Git Notifier - send notification flow:
180+
181+
```plaintext
182+
Receive webhook from git repository
183+
→ packages/laravel-telegram-git-notifier/src/Http/Actions/IndexAction::class
184+
- Check query type (callback_query, message, webhook[gitlab, github])
185+
∟ create new NotificationService
186+
- call the handle method of the NotificationService
187+
188+
→ packages/laravel-telegram-git-notifier/src/Services/NotificationService@handle
189+
- Get and set the event from the request in handleEventFromRequest method
190+
- Call the sendNotification method
191+
192+
→ packages/telegram-git-notifier/src/Trait/EventTrait@handleEventFromRequest
193+
- Set event name
194+
- Check and update platform(GitLab, GitHub) for event object
195+
196+
→ Go to setPlatFormForEvent method
197+
- Detech and set platform file
198+
- Update event config from the platform file
199+
200+
→ Go to sendNotification method of this NotificationService
201+
- Call validateAccessEvent to check if the event is allowed
202+
- Loop through the recipients and send the notification to each recipient
203+
204+
→ packages/telegram-git-notifier/src/Services/NotificationService@validateAccessEvent
205+
- Set payload and message from the event
206+
- Check if the event is allowed in the settings
207+
- Check if the event/action is allowed in the platform settings
208+
209+
→ packages/telegram-git-notifier/src/Structures/Notification@sendNotify
210+
```

0 commit comments

Comments
 (0)