AshDispatch. SMSBackend. Elks
(AshDispatch v0.8.5)
View Source
SMS backend for 46elks, a Nordic SMS provider.
Packaged the way AshDispatch.EmailBackend.Swoosh is: the library owns the
transport, the receipt and the retries, and a concrete provider sits behind
an optional dependency. Here that dependency is req.
Configuration
config :ash_dispatch, :sms_backend, AshDispatch.SMSBackend.Elks
config :ash_dispatch, AshDispatch.SMSBackend.Elks,
username: System.get_env("ELKS_API_USERNAME"),
password: System.get_env("ELKS_API_PASSWORD"),
from: System.get_env("ELKS_SMS_FROM") || "Notify",
dryrun: falseAnd the recipient field, which is easy to forget and whose error message does not say where to look:
config :ash_dispatch,
recipient_fields: [
sms: [identifier: :phone, name: [:display_name, :name]]
]Testing
:req_options is passed straight into Req.post/2, so a stub can be
installed without the backend knowing about the test:
config :ash_dispatch, AshDispatch.SMSBackend.Elks,
req_options: [plug: {Req.Test, MyApp.Elks}]dryrun
Set dryrun: true in dev and test. 46elks then accepts the request,
validates it and answers with an id — but sends nothing and charges nothing.
The receipt is marked :sent with a provider_id prefixed dryrun:, so the
trail is complete without anyone receiving a message.
Sender
An alphanumeric sender id may be at most eleven characters and cannot be replied to. A phone number in E.164 can. 46elks registers alphanumeric senders per account.
Failures not worth retrying
400, 401 and 403 are marked :failed_permanent immediately. A
malformed phone number does not become valid by being sent five more times,
and a wrong password never does — burning the retries on them only delays
telling the person who can fix it.