项目作者: annatel

项目描述 :
Ordered webhooks notifications
高级语言: Elixir
项目地址: git://github.com/annatel/captain_hook.git
创建时间: 2020-09-01T15:02:32Z
项目社区:https://github.com/annatel/captain_hook

开源协议:

下载


CaptainHook

GitHub Workflow Status GitHub issues License Hex.pm Hex.pm

Ordered signed webhook notifications. Support multiple endpoints for each webhook.

Installation

CaptainHook is published on Hex.
The package can be installed by adding captain_hook to your list of dependencies in mix.exs:

  1. def deps do
  2. [
  3. {:captain_hook, "~> 3.0"}
  4. ]
  5. end

After the packages are installed you must create a database migration for each versionto add the captain_hook tables to your database:

  1. defmodule CaptainHook.TestRepo.Migrations.CreateCaptainHookTables do
  2. use Ecto.Migration
  3. def up do
  4. Queuetopia.Migrations.up()
  5. Padlock.Mutexes.Migrations.V1.up()
  6. CaptainHook.Migrations.up()
  7. end
  8. def down do
  9. Queuetopia.Migrations.down()
  10. Padlock.Mutexes.Migrations.V1.down()
  11. CaptainHook.Migrations.down()
  12. end
  13. end

This will run all of CaptainHook’s versioned migrations for your database. Migrations between versions are idempotent and will never change after a release. As new versions are released you may need to run additional migrations.

Now, run the migration to create the table:

  1. mix ecto.migrate

Usage

  1. webhook_endpoint = CaptainHook.create_webhook_endpoint(%{
  2. webhook: "my_webhook_name",
  3. url: "https://webhook.site/538bb308-4dd8-4008-a19b-4e4a5758ef29",
  4. livemode: true,
  5. enabled_notification_patterns: [%{pattern: "*"}]
  6. })
  7. # Get the webhook_endpoint secret in order to verify the webhook signature
  8. %CaptainHook.WebhookEndpoint{secret: secret} =
  9. CaptainHook.get_webhook_endpoint(webhook_endpoint.id, includes: [:secret])
  10. # Notify - it will enqueue the notification and send it in its turn
  11. {:ok, CaptainHook.WebhookNotification{} = webhook_notification} =
  12. CaptainHook.notify(
  13. "my_webhook_name",
  14. true,
  15. "notification_ref",
  16. %{"my" => "data", "to" => "report"}
  17. )

CaptainHook client

Want to verify the authenticity of a captain_hook request ? you can use the CaptainHookClient.

The docs can be found at https://hexdocs.pm/captain_hook.