Skip to content

Commit

Permalink
VM-1516: documentation part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-buravlev committed Jan 14, 2025
1 parent 21d5f0f commit 791fb84
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 19 deletions.
6 changes: 3 additions & 3 deletions docs/01-main-concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In this diagram:

- Black - the implemented message processing mechanism

- Green - an example of implementing communication between the Operator and the Vendor. The Operator works from his workplace based on the VirtoCommerce Platform, the Vendor uses communications on the Vendor Portal. This scenario was implemented in ![VirtoCommerce Marketplace Communication module](https://github.com/VirtoCommerce/vc-module-marketplace-communication)
- Green - an example of implementing communication between the Operator and the Vendor. The Operator works from his workplace based on the VirtoCommerce Platform, the Vendor uses communications on the Vendor Portal. This scenario was implemented in [VirtoCommerce Marketplace Communication module](https://github.com/VirtoCommerce/vc-module-marketplace-communication)

- Orange - a potential scenario for adding messages for the Customer using the VirtoCommerce Frontend application

Expand All @@ -34,7 +34,7 @@ Messages can be collected in _Threads_ - if the sender wishes to indicate that h

Conversations can be edited - you can give them names and icons.

More about the relationships between module classes ![here](/docs/02-data-structure.md)
More about the relationships between module classes [here](/docs/02-data-structure.md)


## Extensibility of message sending methods
Expand All @@ -43,7 +43,7 @@ The module architecture allows to expand the methods of sending messages to user

![VC Communication MessageSenders](media/03-communication-senders.png)

The sending method implemented in VirtoCommerce Communication is also marked in black, and potential Senders are marked in orange. Creating a custom Sender is available in user modules. More details about this ![here](/docs/03-custom-senders.md)
The sending method implemented in VirtoCommerce Communication is also marked in black, and potential Senders are marked in orange. Creating a custom Sender is available in user modules. More details about this [here](/docs/03-custom-senders.md)



54 changes: 54 additions & 0 deletions docs/03-custom-senders.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
# How to create your own sending way

When a user writes a message to someone, this message is not simply saved in the system, it is actually "sent" to the recipients. At the moment, the VirtoCommerce Communication module has only one method of delivering messages to users - using the PushNotification system in the application in which the recipient is authorized.

However, a developer can create his own system for delivering messages to recipients. What is needed for this?

## Create your own class implementing _IMessageSender_

When creating a class, you should pay attention to the SenderName - this is the name under which your custom sender will appear in the system.

`MyMessageSender.cs`
```cs
public class MyMessageSender : IMessageSender
{
public virtual string SenderName { get; } = nameof(MyMessageSender);
public virtual SettingDescriptor[] AvailableSettings { get; set; }
public virtual async Task<SendMessageResult> SendMessage(Message message)
{
// This is where all the magic that the class is created for will be located.
// Sending an email, message in Viber or Teams -
// any system that has the ability to integrate can potentially be used to deliver a message
}
}
```

## Register class in Module.cs

This stage consists of two steps, both of which are done in your project's _Module.cs_ file.

`Module.cs`
```cs
public void Initialize(IServiceCollection serviceCollection)
{
...
// In the Initialize method, you need to add your class to the services collection.
serviceCollection.AddTransient<MyMessageSender>();
...
}
public void PostInitialize(IApplicationBuilder appBuilder)
{
...
// In the PostInitialize method you need to register it
var messageSendersRegistrar = appBuilder.ApplicationServices.GetService<IMessageSenderRegistrar>();
messageSendersRegistrar.Register<MyMessageSender>(() => appBuilder.ApplicationServices.GetService<MyMessageSender>());
...
}
```
## Select new class in the settings

After system restart, go to the settings of the Communications Module and select your class - this will tell the system that it will now be used to send messages.

![VC Communication module settings](media/04-communication-settings.png)

After this, the messages will be delivered in the manner described in the SendMessage method of your _MyMessageSender_ class.


Binary file added docs/media/04-communication-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/VirtoCommerce.CommunicationModule.Core/ModuleConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static class General
{
public static SettingDescriptor CommunicationUserTypes { get; } = new()
{
Name = "Communication.UserTypes",
Name = "CommunicationModule.UserTypes",
GroupName = "Communication|General",
ValueType = SettingValueType.ShortText,
IsDictionary = true,
Expand All @@ -64,7 +64,7 @@ public static class General

public static SettingDescriptor MessageSenders { get; } = new()
{
Name = "Communication.MessageSenders",
Name = "CommunicationModule.MessageSenders",
GroupName = "Communication|General",
ValueType = SettingValueType.ShortText,
DefaultValue = nameof(PushNotificationSender)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
{
"CommunicationModule": {
"blades": {
"hello-world": {
"title": "Hello world blade"
}
}
},
"permissions": {
"CommunicationModule:access": "Open CommunicationModule menu",
"CommunicationModule:create": "Create CommunicationModule related data",
Expand All @@ -15,13 +8,13 @@
},
"settings": {
"CommunicationModule": {
"CommunicationModuleEnabled": {
"title": "CommunicationModule Enabled",
"description": "CommunicationModule Enabled setting"
"MessageSenders": {
"title": "Message Sender",
"description": "Will be used to deliver the message to the recipients"
},
"CommunicationModulePassword": {
"title": "CommunicationModule Password",
"description": "CommunicationModule Password setting"
"UserTypes": {
"title": "CommunicationUser types",
"description": "Available types for CommunicationUsers"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/VirtoCommerce.CommunicationModule.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<moduleType>VirtoCommerce.CommunicationModule.Web.Module, VirtoCommerce.CommunicationModule.Web</moduleType>

<releaseNotes>First version.</releaseNotes>
<copyright>Copyright © 2024 VirtoCommerce. All rights reserved</copyright>
<copyright>Copyright © 2024-2025 VirtoCommerce. All rights reserved</copyright>
<tags>VirtoCommerce Communication module</tags>
<useFullTypeNameInSwagger>false</useFullTypeNameInSwagger>
</module>

0 comments on commit 791fb84

Please sign in to comment.