1. Add a custom channel provider to Creatio
- Click to open the System Designer.
- Go to the System setup block → Lookups.
- Open the Channel provider lookup and add the "Test" value.
2. Set up storage of custom channel data
-
Create a database table and define its structure. The table structure depends on the provider and contains data to send and receive messages. Generally, providers use an authorization token to send messages. To do this, execute the SQL query below.
SQL query that creates the [TestMsgSettings] tableMSSQLPostgreSQL[TestMsgSettings] is a table that stores the custom channel data. Name the table based on the [SomeChannelProviderNameMsgSettings] template, where SomeChannelProviderName is the channel provider name.
-
Register the custom channel in the database. To do this, add a record to the [Channel] table. View the fields to fill out in the table below.
Field Description [Name] The channel name. [ProviderId] The custom provider ID. [MsgSettingsId] The record ID in the [TestMsgSettings] table. [Source] The channel ID in the messenger, such as the Facebook page ID or Telegram client ID. Lets you identify the recipient by a messenger message.
3. Create a web service that receives messages
-
Create a Source code schema.
- Open the Configuration section and select a custom package to add the schema.
-
Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Source Code Designer.
- Set Code to "UsrTestOmnichannelMessagingService."
- Set Title to "TestOmnichannelMessagingService."
Click Apply to apply the changes.
-
Create a web service class.
- Go to the Schema Designer and add the Terrasoft.Configuration.Omnichannel.Messaging namespace.
- Use the using directive to import the namespaces whose data types are utilized in the class.
- Add a class name to match the schema name (the Code property).
- Specify the OmnichannelMessagingService class that contains the basic methods as a parent class.
- Add the [ServiceContract] and [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] attributes to the class.
-
Implement a method (i. e., endpoint) of the web service class. To do this, add the public void ReceiveMessage(TestIncomingMessage message) method to the class in the Source Code Designer. The messenger sends a message to the receive endpoint.
View the source code of the TestOmnichannelMessagingService custom web service below.
- Click Publish on the Source Code Designer’s toolbar to apply the changes to the database level.
4. Implement the conversion of an incoming message
To handle an incoming message, implement the TestIncomingMessageConverter class that converts a message with the TestIncomingMessage type (messenger format message) to the unified Creatio format (the MessagingMessage class).
To create a converter class:
- Open the Configuration section and select a custom package to add the schema.
- Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Source Code Designer.
- Set Code to "UsrTestIncomingMessageConverter."
- Set Title to "TestIncomingMessageConverter."
Click Apply to apply the changes.
-
Add the source code in the Source Code Designer. View the source code of the TestIncomingMessageConverter converter class below.
- Click Publish on the Source Code Designer’s toolbar to apply the changes to the database level.
5. Implement retrieval of user profile data
Messengers provide an API to retrieve data from clients that send messages. To retrieve user profile data, create a class that implements the IProfileDataProvider interface.
To create a class that retrieves user profile data:
- Open the Configuration section and select a custom package to add the schema.
- Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Source Code Designer.
- Set Code to "UsrTestProfileDataProvider."
- Set Title to "TestProfileDataProvider."
Click Apply to apply the changes.
-
Add the source code in the Source Code Designer.
- The class sends a request to the https://graph.test.com/ address to retrieve data in the TestProfileData format (a hypothetical messenger format).
- The class converts the received response into the internal ProfileData format.
- The class adds the retrieved data, for example, first name, last name, and photo, to the internal format when creating a contact. If the request is unsuccessful or data is invalid, the class creates a contact named [New Contact][Channel Name]-[Messenger Client ID].
View the source code of the TestProfileDataProvider class below.
- Click Publish on the Source Code Designer’s toolbar to apply the changes to the database level.
6. Implement ability to download attachments
To download attachments, create the class that implements the IAttachmentsLoadWorker interface:
- Open the Configuration section and select a custom package to add the schema.
- Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Source Code Designer.
- Set Code to "UsrTestAttachmentLoadWorker."
- Set Title to "TestAttachmentLoadWorker."
Click Apply to apply the changes.
-
Add the source code in the Source Code Designer. The AttachmentsDownloader internal class downloads the attachment via a link and saves the attachment to the [OmnichannelMessageFile] database table.
View the source code of the TestAttachmentLoadWorker class below.
- Click Publish on the Source Code Designer’s toolbar to apply the changes to the database level.
7. Implement message sending
To send messages, create a class that implements the IOutcomeMessageWorker interface:
- Open the Configuration section and select a custom package to add the schema.
- Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Source Code Designer.
- Set Code to "UsrTestOutcomeMessageWorker."
- Set Title to "TestOutcomeMessageWorker."
Click Apply to apply the changes.
-
Add the source code in the Source Code Designer. The TestOutcomeMessageWorker class converts the message to messenger format and sends it using the messenger API. The class can send the message using a token. Store the token in the [TestMsgSettings] database table. UserConnection passed in the constructor provides access to the table. The class sends a message to the https://graph.test.com/ address using the internal HttpRequestSender class.
View the source code of the TestOutcomeMessageWorker class below.
- Click Publish on the Source Code Designer’s toolbar to apply the changes to the database level.
8. Link the interfaces
To link the interfaces, create a class.
To create a class:
- Open the Configuration section and select a custom package to add the schema.
- Click Add → Source code on the section list toolbar.
-
Fill out the schema properties in the Source Code Designer.
- Set Code to "UsrTestAppEventListener."
- Set Title to "TestAppEventListener."
Click Apply to apply the changes.
-
Add the source code in the Source Code Designer. Specify the AppEventListenerBase class as a parent class. The Test tag links the created classes. Specify the tag in the ChannelName field on step 4. Creatio uses a tag to identify the files required to retrieve profile data, upload attachments, and send messages.
View the source code of the TestAppEventListener class below.
- Click Publish on the Source Code Designer’s toolbar to apply the changes to the database level.