Question

Override sending messages to custom channel provider logic

Hi there! We are developing an application and want to add a custom channel provider. We follow this guide and stuck on 7. Implement message sending step. 

 

The question in the send messages logic though Creatio interface. 

Let's assume we already have an active chat with some contact and messages from the contact. If we send (outcoming) message to the chat, we will only see a modal window with "Error while sending the message" message.

We checked the request made when sending the message. The request URL is .../0/rest/OmnichannelOutcomeMessagingService/SendMessage, and the payload:

{
  "message": {
    "Attachments": null,
    "ChannelId": "e79043bc-377d-46b9-86ee-9b0fc4845f0b",
    "ChatId": "f2374931-2402-411a-bf37-0eb2a6acd422",
    "ContactIdentification": null,
    "Id": "00000000-0000-0000-0000-000000000000",
    "IsEcho": false,
    "IsGuestUser": false,
    "IsStandBy": false,
    "Message": "test",
    "MessageDirection": 2,
    "MessageType": 0,
    "Recipient": "Test User",
    "Sender": "123",
    "Source": 2,
    "Timestamp": 0
  }
}

 

We also have an IOutcomeMessageWorker interface implementation binded with our "Test" channel (which has Source set to "123" as you can notice from the payload).

We tried to call the OmnichannelMessagingService.InternalSend method with the same MessagingMessage and saw the following stack trace:

The server encountered an error processing the request. The exception message is 'Error creating an instance
			of the "OmnichannelProviders.MessageWorkers.IOutcomeMessageWorker" class'. See server logs for more details.
			The exception stack trace is: 
		    at Terrasoft.Core.Factories.ClassFactory.GetInstance[T](Func`1 action)
			at OmnichannelMessaging.MessageWorkerFactory`1.GetWorkerInstance(String messengerName)
			at OmnichannelMessaging.MessageOutcomeWorker.InternalSend(UnifiedMessage message, String messenger)
			at Terrasoft.Configuration.Omnichannel.Messaging.OmnichannelMessagingService.InternalSend(MessagingMessage
			messagingMessage)
			at Terrasoft.Configuration.Omnichannel.Messaging.CusboOmnichannelMessagingService.test()
			at Terrasoft.Configuration.CusboMessageEventsHandlerWebServiceNamespace.CusboEventHandlerWebService.test()
			at SyncInvoketest(Object , Object[] , Object[] )
			at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&
			outputs)
			at Terrasoft.Web.Common.ServiceModel.ThreadContextInitializer.Invoke(Object instance, Object[] inputs,
			Object[]& outputs)
			at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
			at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
			at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
			at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

 

If we add MessagingMessage.Channel = "Test", the message is sent successfully. So we wonder if we are missing something in our configuration and how to send the message to the custom channel provider. Or if there is a way to call custom logic (endpoint, service, anything) when sending messages to custom channel provider.

 

Thanks in advance.

 

Like 0

Like

1 comments

As far as we see, there is a problem in the existing method OmnichannelOutcomeMessagingService.SendMessage - when the message is sent from omni chat conversation component, the request body does not contain ChannelName property (if we trigger this endpoint with this value set, everything works).



The workaround we have done: added Harmony library to the app and used patching with the following code in our custom class that extend AppEventListenerBase (in the end of the OnAppStart method): 

var original = typeof(OmnichannelOutcomeMessagingService).GetMethod("SendMessage");
var prefix = typeof(SendMessagePatcher).GetMethod("Prefix");
var harmony = new Harmony("com.example.test");
harmony.Patch(original, prefix: new HarmonyMethod(prefix));

(SendMessagePatcher should be implemented separately, with adding ChannelName in case the message was sent into custom channel provider chat).



If you have any other suggestions of implementing message sending for custom channel provider, please let us know.

If Creatio Developers consider that there is a bug, we hope it would be fixed asap, otherwise we hope that the documentation would be updated as it is either outdated or not covering adding custom channel provider case completely (especially sending messages topic).

 

Show all comments