Viberex v0.2.1 Viberex.Server View Source

Server that handle callbacks from Viber. All available events you can see here Callbacks

Usage

Write callbacks handler. The handle_callback function must return :noreply or {:reply, message} if callback wait response, e.g. welcome message.

defmodule MyApp.Handler do
  use Viberex.Server

  def handle_callback(%{"event" => "conversation_started"}) do
    welcome_message = %{
      text: "Hi!",
      type: "text"
    }
    {:reply, welcome_message}
  end

  def handle_callback(_), do: :noreply
end

Add the handler to supervisor

defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    import Supervisor.Spec

    # Set args `reqest_path` and `port`
    children = [
      worker(MyApp.Handler, ["/webhook/viber", 8000])
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end