ExLine.EventHandler behaviour (ExLine v0.1.0)

Copy Markdown View Source

Behaviour + convenience macro for implementing LINE event handlers dispatched by ExLine.EventRouter.

use ExLine.EventHandler imports ExLine.Message (so builders like text/1 are available), enforces the handle_event/3 callback, and defines the call/3 wrapper the router calls.

Message sending takes a client, so call ExLine.Api.Messaging explicitly with the client you placed in event_assigns:

defmodule MyApp.HelpHandler do
  use ExLine.EventHandler

  @impl true
  def handle_event(:show_help, %{"replyToken" => token}, %{client: client}) do
    ExLine.Api.Messaging.reply(client, token, text("Need help?"))
    :ok
  end
end

Summary

Callbacks

handle_event(action, event, event_assigns)

@callback handle_event(action :: atom(), event :: map(), event_assigns :: map()) ::
  :ok | {:error, any()}