A wrapper for the Flowroute telephony API, currently supporting the Messaging v2.1 component.
If available in Hex, the package can be installed
by adding flowroute
to your list of dependencies in mix.exs
:
def deps do
[
{:flowroute, "~> 0.1.0"}
]
end
Set your Flowroute API credentials in your config.exs
:
config :flowroute,
access_key: System.get_env("FLOWROUTE_ACCESS_KEY"),
secret_key: System.get_env("FLOWROUTE_SECRET_KEY")
send(:sms, from, to, payload \\ [], options \\ [])
The from
and to
phone numbers are required by Flowroute to be in E.164 format, but no validation is done by this library. See ex_phone_number if you are looking for E.164 validation.
iex> Flowroute.Message.send(:sms, "15551230000", "15551234444", body: "Hello there!")
{:ok,
%{
"data" => %{
"id" => "mdr2-f3ce388895a711e89295768a2c7516d2",
"links" => %{
"self" => "https://api.flowroute.com/v2.1/messages/mdr2-f3ce388895a711e89295768a2cffffff"
},
"type" => "message"
}
}}
Flowroute.Message.send(:mms, "15551230000", "15551234444",
body: "Enjoy this donut",
media_urls: ["https://upload.wikimedia.org/wikipedia/commons/b/bb/Donut_879.png"])
iex(2)> Flowroute.Message.mdr("mdr2-f3ce388895a711e89295768a2c7516d2")
{:ok,
%{
"data" => %{
"attributes" => %{
"delivery_receipts" => [],
"status" => "mmsc submit",
...
},
"id" => "mdr2-f3ce388895a711e89295768a2c7516d2",
...
},
...
}}
iex(3)> Flowroute.Message.mdr_list("2018-08-01", limit: 2, end_date: "2018-08-31")
{:ok,
%{
"data" => [
%{
"attributes" => %{
"amount_display" => "$0.0040",
"amount_nanodollars" => 4000000,
"body" => "This is a test of the yoyoyo system!",
"delivery_receipts" => [
...
]
},
...
},
%{
"attributes" => %{
"amount_display" => "$0.0040",
"amount_nanodollars" => 4000000,
"body" => "This is a test of the yoyoyo system!",
"delivery_receipts" => [
...
]
},
...
}
]
}}
iex(4)> Flowroute.Message.mdr_list!("2018-08-01", limit: 1) |> Flowroute.Message.tally_cost()
0.004
iex(5)> Flowroute.Message.mdr_list!("2018-08-01") |> Flowroute.Message.tally_cost()
0.057
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/flowroute.