View Source CozyLark.EventSubscription (cozy_lark v0.4.1)

Provides utilities of handling event subscription.

Read more at Subscribe to events.

WARNING

Only the V2.0 events are supported.

basic-concepts

Basic concepts

the-process-of-subscription

the process of subscription

  1. setup verification_token and encrypt_key
  2. configure the request URL
  3. add events
  4. apply for scopes
  5. receive and process events

Utilities provided by this module can be used at:

  • step 2
  • step 5

supported-events

supported events

The full list of events can be found at Getting Started - Event list.

usage

Usage

defmodule Demo.EventHandler do
  alias CozyLark.EventSubscription
  alias CozyLark.EventSubscriptionConfig

  def process_event(payload) do
    EventSubscription.receive_event(config(), payload,
      security_verification_method: :verification_token
    )
  end

  def config() do
    :demo
    |> Application.fetch_env!(__MODULE__)
    |> Enum.into(%{})
    |> Config.new!()
  end

end

# config/runtime.exs
config :demo, Demo.EventHandler,
  verification_token: System.fetch_env!("FEISHU_EVENT_SUBSCRIPTION_VERIFICATION_TOKEN")
  encrypt_key: System.fetch_env!("FEISHU_EVENT_SUBSCRIPTION_ENCRYPT_KEY")

more-details

More details

Link to this section Summary

Link to this section Types

@type payload() :: map()
@type response() ::
  {:ok, {:challenge, String.t()}}
  | {:ok, {:event, CozyLark.EventSubscription.Event.t()}}
  | {:error, {:unknown_event, term()}}
  | {:error, :bad_verification_token}
  | {:error, :bad_signature}

Link to this section Functions