Contribute an Adapter
Last updated
Was this helpful?
Last updated
Was this helpful?
Adapters convert information provided by channels (SMS, Whatsapp) for each specific provider to xMessages and vise versa.
Setup the adapter repository to start working on it. Follow the steps given to add a new adapter & test it.
Fork the below repository & clone it.
https://github.com/samagra-comms/adapter/
Checkout to the latest stable master branch.
Open the project in any IDE spring/intellij.
Follow to create a new adapter.
Write test cases for inbound method convertMessageToXMsg
& outbound method processOutBoundMessageF
.
A simple example to test the send text message is given in the .
All adapters are named as <ProviderName><ChannelName>Adapter
; for example GupshupWhatsappAdapter. Adapters should extend AbstractProvider
and implement IProvider
. Thus, it needs to implement the following methods:
public Mono<XMessage> convertMessageToXMsg(Object msg) // Converts API response object to XMessage
public Mono<XMessage> processOutBoundMessageF(XMessage nextMsg) //Converts XMessage object to API response and call it.
These methods are called by inbound
and outbound
services internally to process the incoming and outgoing messages.
We can also send media/location/quickReplyButton/list messages to user. As we are using the ODK forms, we use bind::stylingTags, bind::caption to show the media file or to show the select choices as list/quick reply buttons. There are a few constraints which will be applied with the quickReplyButton/list content.
Below are the few styling tags we have allowed for now.
image //To send image file
audio //To send audio file
video //To send video file
document //To send document file
buttonsForListItems //To send choices as quick reply buttons
list //To send choices as list
Sample code to receive a text message from channel & reply to channel.
Create a new provider class which implements IProvider.
Implement convertMessageToXMsg method for converting incoming message from channel to XMessage format.
Implement processOutBoundMessageF method to reply to channel by converting XMessage format to channel message format.
Create a web service class that handles api which is used to reply to channel.
Create a class for format which is accepted by reply to channel api Eg. http://example.com/replyMessageToChannel.
Create a message format class for OutboundMessage class property.
Create a class that accepts response from channel reply api.
Create a class that accepts format for message received from channel.
All adapters with the above implementation will be valid. An example adapter can be found .
Currently we accepts text/media/location/quickReplyButton/list messages. It should be implemeted according to the network provider(Netcore/Gupshup) .
To enable these, we have to add them in convertMessageToXMsg
and convert these according to the
We can send a text message to user. This is the basic usage of an adapter. When creating a new adapter we should start with this scenario. A sample code for the same is also added .
To send this type of content to user, adapter should implement it according to the network provider(Netcore/Gupshup) .
To make a bot use this adapter we will have to later add this adapter configuration in databse using the API. This adapter may require you to have some credentials, which can be stored in a vault service. to see how to add a secret in vault.
If we want to fetch the credentials of the adapter from vault service, see the code of to check how to do this.
After the adapter is created we should be able to implement it in inbound & outbound service for receiving and sending messages to user. to see the process & sample code on how to to do this.