Clova v0.5.0 Clova.DispatcherPlug View Source

A plug for dispatching CEK request to your Clova implementation.

For simple skills, Clova.SkillPlug provides a wrapper of this and related plugs.

Pass your callback module as the dispatch_to argument to the plug.

This plug expects the request to have been parsed by Plug.Parsers, and validated by Clova.ValidatorPlug.

The Clova.Response struct returned from your Clova implementation is placed into the :clova_response assign. To encode it to JSON, the Clova.EncoderPlug can be used.

If you do not use Clova.EncoderPlug, you need to encode and set the Plug.Conn’s response body yourself:

plug Plug.Parsers,
  parsers: [:json],
  json_decoder: Poison,
  body_reader: Clova.CachingBodyReader.spec()

plug Clova.ValidatorPlug, app_id: "com.example.my_extension"
plug Clova.DispatcherPlug, dispatch_to: MyExtension

plug :match
plug :dispatch

post "/endpoint" do
  conn
    |> put_resp_content_type("application/json")
    |> send_resp(conn.status, Poison.encode!(conn.assigns.clova_response))
end

Link to this section Summary

Functions

Callback implementation for Plug.call/2

Callback implementation for Plug.init/1

Link to this section Functions

Callback implementation for Plug.call/2.

Callback implementation for Plug.init/1.