Developer Manual v1.3.0, v1.4.0


Creation of a new SMS connector (broker)

But you can also write your own SMS broker implementation. To do this, you'll need to declare a new extension point in the plugin.xml file of a plugin Ametys . If necessary, you'll need to create a new plugin, then follow the instructions on the Architecture page of plugin Ametys .

Step 1: In a plugin.xml file, start by declaring your extension point and any configuration parameters required for sending SMS, as in the example below:

<feature name="com.mycompany.cms.sms.broker.mybroker">
        <config>
            <param id="com.mycompany.cms.sms.broker.user" type="string">
                <label i18n="false">Identifiant</label>
                <description i18n="true">Identifiant</description>
                <validation>
                    <mandatory/>
                </validation>
                <category i18n="true">plugin.sms:PLUGINS_SMS_SUBSCRIPTION_SERVICE_BROKER_CATEGORY</category>
                <group i18n="true">plugin.sms:PLUGINS_SMS_SUBSCRIPTION_SERVICE_SERVICE_CONNECTION_GROUP</group>
                <order>1</order>
            </param>
            <param id="com.mycompany.cms.sms.broker.password" type="password">
                <label i18n="false">Mot de passe</label>
                <description i18n="false">Mot de passe</description>
                <validation>
                    <mandatory/>
                </validation>
                <category i18n="true">plugin.sms:PLUGINS_SMS_SUBSCRIPTION_SERVICE_BROKER_CATEGORY</category>
                <group i18n="true">plugin.sms:PLUGINS_SMS_SUBSCRIPTION_SERVICE_SERVICE_CONNECTION_GROUP</group>
                <order>2</order>
            </param>
        </config>
        <extensions>
            <extension point="org.ametys.plugins.sms.broker.Broker"
                       id="com.mycompany.cms.sms.broker.MyBroker"
                       class="com.mycompany.cms.sms.broker.MyBroker"
                       logger="com.mycompany.cms.sms.broker.MyBroker">
            </extension>
        </extensions>
</feature>

Step 2: Then write the class com.mycompany.cms.sms.broker.MyBroker :

public class MyBroker extends LoggerBroker 
{
	@Override
    public void send(Set<String> phoneNumbersList, String message, String listId) throws Exception
    {   
		super.send(phoneNumbersList, message, listId);
		// Do it: send SMS to all the phones in the list
	}

	@Override
    public String getPhoneNumberFromStopRequest() throws Exception
    {
		// Do it ...
	}
}

The method send is responsible for sending mail. For example, use your provider's web service to send SMS messages.

The method getPhoneNumberFromStopRequest is responsible for extracting the telephone number wishing to unsubscribe from the service from the HTTP request sent by the provider (broker). For example, for Etoile Diesethe number is contained in the query parameter "num" : http://<monsite.com>/_plugins/sms/stop-sms?num=336xxxxxxxx&txt=STOP

 

Step 3: Finally, select your broker in the WEB-INF/param/runtime.xml

<org.ametys.plugins.sms.broker.Broker>com.mycompany.cms.sms.broker.MyBroker</org.ametys.plugins.sms.broker.Broker>

Step 4: Restart the server.

Back to top

SMS