Skip to content

Commit

Permalink
Update twilio_messaging.md
Browse files Browse the repository at this point in the history
  • Loading branch information
excid3 authored Jan 18, 2024
1 parent ee27b56 commit 7d1a20f
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions docs/delivery_methods/twilio_messaging.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
### Twilio Messaaging Delivery Method
# Twilio Messaaging Delivery Method

Sends an SMS or Whatsapp message via Twilio Messaging.

`deliver_by :twilio_messaging`

##### Options

* `message` - *Required*

Message is required and needs to be passed in as part of the params:

```ruby
SmsNotification.with(message: "Howdy!")
```

* `credentials: :get_twilio_credentials` - *Optional*

Use a custom method to retrieve the credentials for Twilio. Method should return a Hash with `:account_sid`, `:auth_token` and `:phone_number` keys.

Defaults to `Rails.application.credentials.twilio[:account_sid]` and `Rails.application.credentials.twilio[:auth_token]`

* `url: :get_twilio_url` - *Optional*
```ruby
deliver_by :twilio_messaging do |config|
config.json = ->{
{
From: phone_number,
To: recipient.phone_number,
Body: params.fetch(:message)
}
}

Use a custom method to retrieve the Twilio URL. Method should return the Twilio API url as a string.
config.credentials = {
phone_number: Rails.application.credentials.dig(:twilio, :phone_number),
account_sid: Rails.application.credentials.dig(:twilio, :account_sid),
auth_token: Rails.application.credentials.dig(:twilio, :auth_token)
}
# config.credentials = Rails.application.credentials.twilio
# config.phone = "+1234567890"
# config.url = "https://api.twilio.com/2010-04-01/Accounts/#{account_sid}/Messages.json"
end
```

## Content Templates

```ruby
deliver_by :twilio_messaging do |config|
config.json = -> {
{
From: "+1234567890",
To: recipient.phone_number,
ContentSid: "value", # Template SID
ContentVariables: {1: recipient.first_name}
}
}
end
```

Defaults to `"https://api.twilio.com/2010-04-01/Accounts/#{twilio_credentials(recipient)[:account_sid]}/Messages.json"`
## Options

* `format: :format_for_twilio` - *Optional*
* `json` - *Optional*

Use a custom method to define the payload sent to Twilio. Method should return a Hash.

Expand All @@ -39,3 +53,15 @@ Sends an SMS or Whatsapp message via Twilio Messaging.
To: recipient.phone_number
}
```

* `credentials` - *Optional*

Retrieve the credentials for Twilio. Should return a Hash with `:account_sid`, `:auth_token` and `:phone_number` keys.

Defaults to `Rails.application.credentials.twilio[:account_sid]` and `Rails.application.credentials.twilio[:auth_token]`

* `url` - *Optional*

Retrieve the Twilio URL. Should return the Twilio API url as a string.

Defaults to `"https://api.twilio.com/2010-04-01/Accounts/#{twilio_credentials(recipient)[:account_sid]}/Messages.json"`

0 comments on commit 7d1a20f

Please sign in to comment.