mix letterbox.install (Letterbox v0.1.0-rc.0)

Copy Markdown View Source

Installs Letterbox in a Phoenix application.

$ mix igniter.install letterbox

or, with Letterbox already in the deps, mix letterbox.install. Igniter shows each change as a diff before it writes, and running the task again changes nothing:

  • the router has the ingresses' webhooks, in a pipeline of their own with no session and no CSRF token:

    pipeline :webhooks do
      plug :accepts, ["json"]
    end
    
    scope "/inbound" do
      pipe_through :webhooks
      post "/webhooks/:ingress", Letterbox.Plug, []
    end

    The app's to change: the path, the scope and the pipeline (see Letterbox.Plug). Run again, the task finds the route by its plug, wherever it is, and adds no other.

  • the migration of Letterbox's table (mix letterbox.gen.migration);

  • .formatter.exs imports Letterbox's, so routes are written route "support@", to: …;

  • config :letterbox, repo: MyApp.Repo, routing: MyApp.Mailboxes;

  • lib/my_app/mailboxes.ex, the routes, which give every message to lib/my_app/mailboxes/inbox.ex, a first mailbox that logs what it gets: the app's own files, written once;

  • the application starts Letterbox.Sweeper after the repo: messages that were waiting are resumed, and those done with for 30 days are deleted.

  • the endpoint's Plug.Parsers keeps a webhook's body as it was sent, for its signature (PhoenixMountable.RawBody).

Then say how messages reach the app, in config/runtime.exs (Letterbox.Ingress).