A Nexmo API client for Elixir.
You can find the hex package here, and the docs here.
def deps do
[{:ex_nexmo, "~> 0.1.2"}]
end
Add the :ex_nexmo
application as your list of applications in mix.exs
:
def application do
[applications: [:logger, :ex_nexmo]]
end
Then run $ mix do deps.get, compile
to download and compile your dependencies.
You'll need to set a few config parameters, some in your app config, some, like
API credentials, we recommend keeping as environment viarables: take a look in
the lib/config.ex
file to see what is required.
Then sending a text message is as easy as:
ExNexmo.send_sms(from, to, message)
ExNexmo includes a Plug that allows for preview of sent messages in the
browser. A sample of the required config is in config/dev.exs
:
use Mix.Config
config :ex_nexmo, use_local: true
Setting the use_local
config option will cause messages to be stored locally
in-memory, allowing you to see what would have been sent to the recipient.
If you're using Phoenix, for example, you could use it like this:
# in web/router.ex
if Mix.env == :dev do
scope "/dev" do
pipe_through [:browser]
forward "/sms", Plug.ExNexmo.MessagePreview, [base_path: "/dev/sms"]
end
end