Introduction
How to enable Twilio Connector ?
2. Upload the connector to the ESB instance as below.
3. Once the connector is successfully uploaded, it's required to “enable” the connector in order to activate. For that click on List under Connectors in Main tab and click on disabled in Status column to enable it.
Example
This example basically describes how to send an SMS through Twilio utilizing WSO2 Twilio Connector. First of all you should have to setup a trial account to test this scenario in Twilio if you haven't an account yet please create one. Once you created an account you can able to get Account SID and Auth Token when you go to Dashboard Console. These tokens are essential to initialize the connector in your Proxy Service.
For enabling a phone number to send and receive SMS in Twilio click here. Please refer this for more information.
To use the Twilio connector, add the
<twilio.init>
element in your configuration before any other Twilio operations. This
Twilio configuration authenticates with Twilio by specifying the SID and
auth token of your master Twilio account. You can find your SID and token by logging into your Twilio account and going to the API Credentials section on the dashboard.<
twilio.init
>
<
accountSid
>ACba8bc05eacf94afdae398e642c9cc32d</
accountSid
>
<
authToken
>AC5ef8732a3c49700934481addd5ce1659</
authToken
>
</
twilio.init
>
For best results, save the Twilio configuration as a local entry. You can then easily reference it with the configKey attribute in your Twilio operations. For example, if you saved the above <twilio.init> entry as a local entry named MyTwilioConfig, you could reference it from an operation like as follows.
1. Go to Local Entries under Service Bus in Main tab and click on Add Local Entries.
2. Then Click on Add in-lined XML Entry and give configuration as below.
3. Now click on Save button to save the content.
4. Configure your proxy as below.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="testTwillio"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="name"
expression="get-property('myName')"
scope="default"
type="STRING"/>
<property name="phone"
expression="get-property('myPhone')"
scope="default"
type="STRING"/>
<property name="smsContent"
expression="fn:concat('WSO2 Twilio Connector : SMS Generated! - Name : ', get-property('name'))"
scope="default"
type="STRING"/>
<twilio.sendSms configKey="MyTwilioConfig">
<body>{get-property('smsContent')}</body>
<to>{get-property('phone')}</to>
<from>+14843160720</from>
</twilio.sendSms>
<respond/>
</inSequence>
</target>
</proxy>
If configKey is not saved or updated, please go to <ESB_HOME>/repository/deployment/server/synapse-configs/default/proxy-services directory and open your proxy service xml file and apply changes there and save it.
5. For testing the proxy service, click on Try this service and Send the message via SOAP UI.
6. Finally you can see the server output as below.
No comments:
Post a Comment