SMS gateway configuration
If you want to verify your users by sending a verification code via SMS (mobile/cell phones text messages) you need to provide a SMS gateway service class.
An example class would be something like:
class MySMSGatewayService
attr_reader :mobile_phone_number, :code, :context
def initialize(mobile_phone_number, code, context = {})
@mobile_phone_number = mobile_phone_number
@code = code
@context = context
end
def deliver_code
# Actual code to deliver the code
true
end
end
The arguments provided for the initialize method are:
-
mobile_phone_number
- The full mobile phone number to send the message to, containing the country code. -
code
- The code or the message to be sent to the given mobile phone number. -
context
- An extra context attribute which can be used to pass e.g. the correct organization for the gateway to utilize.
Then you will need to configure it with the help of Environment Variables:
export DECIDIM_SMS_GATEWAY_SERVICE="MySMSGatewayService"
You can find an example on how this is set up at DecidimBarcelona’s app/services/sms_gateway.rb. Your final implementation will depend on how your SMS provider works.
Another example which also utilizes the context
argument can be found from the Twilio SMS integration available at:
https://github.com/Pipeline-to-Power/decidim-module-ptp/blob/aa82286d91d404e83ea16a55d281a1b049bbaca2/decidim-sms-twilio/lib/decidim/sms/twilio/gateway.rb