Adapter Implementation
Last updated
Was this helpful?
Last updated
Was this helpful?
A new adapter can be created using this . Once the adapter is created we can incorporate this apater in inbound and outbound service for receiving and sending message to user respectively.
Below is the process on how to implement a adapter in inbound & outbound.
Inbound receives the messages from a channel, and uses the channel adapter to convert it to XMessage format. Once the messages is converted it will get processed.
When a new adapter is created we will have to add a class that will receive the messages from channel and use the adapter to convert this message to XMessage.
In the next section of the document, we will see the sample code for the same.
Follow the steps below to setup the inbound repository to start working on it.
Fork the below repository & clone it.
https://github.com/samagra-comms/inbound/
Checkout to the recent stable master
branch.
Open the project in any IDE spring/intellij.
Follow the next steps.
Create a class for the channel & provider for the adapter created. Eg. NetcoreWhatsappController.
Once the class is create, we can use the link http://host:port/provider/channel to receive messages from user. A user will receive a message in below format.
A sample api to receive messages from user is given below.
Below are some of the existing implementation code of currently available adapters.
Outbound converts the xMessage to the one that will be sent to the channel(sms/whatsapp). It will then be sent to the network provider who will send it to the channel using the implementation done in adapter.
Add code to return adapter object based on the channel & provider set in XMessage.
Once the code is added, we should be able to use the new adapter to sent messages to user.
Outbound uses this class to send messages to user. There is class called which uses the channel & provider set in the XMessage and return the adapter object which will be used to call the processOutBoundMessageF method.