Sha256: df8618d55c9e37d94237bfc4403f6c08cef578d3a16b9aa0c57d5d0dd9a8fe5d
Contents?: true
Size: 1.74 KB
Versions: 7
Compression:
Stored size: 1.74 KB
Contents
= SMS If you want to verify your users by sending a verification code via SMS you need to provide a SMS gateway service class through the xref:configure:initializer.adoc[initializer]. This service can also be used by some spaces (such as xref:admin:spaces/votings.adoc[Votings]), and external modules could use it too. An example class would be something like: [source,ruby] .... 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 in the Decidim initializer: [source,ruby] .... config.sms_gateway_service = "MySMSGatewayService" .... You can find an example on how this is set up at https://github.com/AjuntamentdeBarcelona/decidim-barcelona/blob/672f5a8938d884940899b4304f0a17e25d42d2a0/app/services/sms_gateway.rb[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
Version data entries
7 entries across 7 versions & 1 rubygems