Add Decidim Twilio SMS configuration setup

This commit is contained in:
Disassembler 2021-04-18 11:52:33 +02:00
parent c9af05aeb0
commit 9be07a4626
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
5 changed files with 42 additions and 8 deletions

View File

@ -1,5 +1,5 @@
{
"version": "0.23.5-210408",
"version": "0.23.5-210416",
"meta": {
"title": "Decidim",
"desc-cs": "Platforma pro účast občanů",
@ -8,7 +8,7 @@
},
"containers": {
"decidim": {
"image": "decidim_0.23.5-210408",
"image": "decidim_0.23.5-210416",
"depends": [
"decidim-postgres"
],

View File

@ -1,4 +1,4 @@
IMAGE decidim_0.23.5-210408
IMAGE decidim_0.23.5-210416
FROM decidim-nginx_1.18.0-210106
# https://github.com/Platoniq/decidim-install/blob/master/decidim-bionic.md

View File

@ -38,6 +38,7 @@ group :production do
gem "passenger"
gem "delayed_job_active_record"
gem "daemons"
gem "twilio-ruby"
end
# Modules

View File

@ -4,4 +4,8 @@ SMTP_USERNAME: "admin@example.com"
SMTP_PASSWORD: ""
SMTP_ADDRESS: "decidim-smtp"
SMTP_DOMAIN: "example.com"
HERE_API_KEY: ""
TWILIO_ACCOUNT_SID: ""
TWILIO_AUTH_TOKEN: ""
TWILIO_SENDER_NUMBER: ""
RAILS_LOG_TO_STDOUT: "1"

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true
require "twilio-ruby"
Decidim.configure do |config|
# The name of the application
config.application_name = "Decidim"
@ -33,10 +35,12 @@ Decidim.configure do |config|
# config.force_ssl = true
# Geocoder configuration
# config.geocoder = {
# static_map_url: "https://image.maps.ls.hereapi.com/mia/1.6/mapview",
# here_api_key: Rails.application.secrets.geocoder[:here_api_key]
# }
if !ENV["HERE_API_KEY"].to_s.empty?
config.geocoder = {
static_map_url: "https://image.maps.ls.hereapi.com/mia/1.6/mapview",
here_api_key: ENV["HERE_API_KEY"]
}
end
# Custom resource reference generator method. Check the docs for more info.
# config.reference_generator = lambda do |resource, component|
@ -126,7 +130,32 @@ Decidim.configure do |config|
# end
# end
#
# config.sms_gateway_service = "MySMSGatewayService"
class TwilioSMSGatewayService
attr_reader :mobile_phone_number, :code
def initialize(mobile_phone_number, code)
@mobile_phone_number = mobile_phone_number
@code = code
end
def deliver_code
Rails.logger.debug("Twilio SMS gateway service, verification code is: #{code}, should have been delivered to #{mobile_phone_number}")
client.messages.create(
from: ENV["TWILIO_SENDER_NUMBER"],
to: mobile_phone_number,
body: code
)
end
def client
::Twilio::REST::Client.new ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_AUTH_TOKEN"]
end
end
if !ENV["TWILIO_ACCOUNT_SID"].to_s.empty?
config.sms_gateway_service = "TwilioSMSGatewayService"
end
# Timestamp service configuration
#