↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Sending an SMS with Phoenix

The walkthrough starts with a new Phoenix app and shows how to install dependencies, create the database, and run the server. It then adds a Nexmo account, API credentials, and a virtual number so the app can send SMS messages.

It also defines the routes, controller actions, templates, and environment variables needed for the app to submit a text message and show a success page.

Reading notes
#

  • Phoenix is presented as the main web framework in the Elixir ecosystem, with an intuitive setup and low barrier to entry.
  • The app is created with mix phx.new sms_app, then the database is created with mix ecto.create and the server is started with mix phx.server.
  • A Nexmo account is created for free, and the user fetches API credentials from the dashboard.
  • For sending SMS in the US, the tutorial says a Nexmo virtual number must be purchased and used as the originating phone number.
  • The router gets three routes: GET /sms, POST /send, and GET /update.
  • index/2 renders the form and supplies a CSRF token.
  • send/2 uses HTTPoison to post to the Nexmo SMS API with the API key, API secret, sender number, message text, and recipient number.
  • If the message succeeds, the controller redirects to update/2; otherwise it shows an error.
  • The tutorial adds httpoison as a dependency in mix.exs and installs it with mix deps.get.
  • The view module and two templates are created for the SMS form and the success page.
  • The form posts the recipient number and message, and includes the CSRF token as a hidden field.
  • The app reads NEXMO_API_KEY, NEXMO_API_SECRET, and NEXMO_NUMBER from a .env file, which should be kept out of GitHub.