{"id":32170718,"url":"https://github.com/knocklabs/knock-elixir","last_synced_at":"2026-02-19T20:00:57.840Z","repository":{"id":40558748,"uuid":"365559374","full_name":"knocklabs/knock-elixir","owner":"knocklabs","description":"Official Elixir SDK for interacting with the Knock API.","archived":false,"fork":false,"pushed_at":"2025-11-04T19:58:16.000Z","size":97,"stargazers_count":27,"open_issues_count":3,"forks_count":11,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-11-04T21:23:50.280Z","etag":null,"topics":["elixir","knocklabs","notifications"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knocklabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-05-08T16:18:18.000Z","updated_at":"2025-10-17T01:03:18.000Z","dependencies_parsed_at":"2023-01-31T05:15:43.474Z","dependency_job_id":"4bd031d5-bcee-4d19-97ac-a157006c6b8b","html_url":"https://github.com/knocklabs/knock-elixir","commit_stats":{"total_commits":42,"total_committers":6,"mean_commits":7.0,"dds":"0.40476190476190477","last_synced_commit":"69fd3f37752b8fb0e249b86f18bb241814512c9d"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/knocklabs/knock-elixir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knocklabs%2Fknock-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knocklabs%2Fknock-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knocklabs%2Fknock-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knocklabs%2Fknock-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knocklabs","download_url":"https://codeload.github.com/knocklabs/knock-elixir/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knocklabs%2Fknock-elixir/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29629632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T18:02:07.722Z","status":"ssl_error","status_checked_at":"2026-02-19T18:01:46.144Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","knocklabs","notifications"],"created_at":"2025-10-21T17:03:12.423Z","updated_at":"2026-02-19T20:00:57.834Z","avatar_url":"https://github.com/knocklabs.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Knock\n\nKnock API access for applications written in Elixir.\n\n## Documentation\n\nSee the [package documentation](https://hexdocs.pm/knock) as well as [API documentation](https://docs.knock.app) for usage examples.\n\n## Installation\n\nAdd the package to your `mix.exs` file as follows:\n\n```elixir\ndef deps do\n  [\n    {:knock, \"~\u003e 0.4\"}\n  ]\nend\n```\n\n## Configuration\n\nStart by defining an Elixir module for your Knock instance:\n\n```elixir\ndefmodule MyApp.Knock do\n  use Knock, otp_app: :my_app\nend\n```\n\nTo use the library you must provide a secret API key, provided in the Knock dashboard.\n\nYou can set it as an environment variable:\n\n```bash\nKNOCK_API_KEY=\"sk_12345\"\n```\n\nOr you can specify it manually in your configuration:\n\n```elixir\nconfig :my_app, MyApp.Knock,\n  api_key: \"sk_12345\"\n```\n\nOr you can pass it through when creating a client instance:\n\n```elixir\nknock_client = MyApp.Knock.client(api_key: \"sk_12345\")\n```\n\nTo use a branch, set the `branch` option in your configuration or client instance:\n\n```elixir\nconfig :my_app, MyApp.Knock,\n  api_key: \"sk_12345\"\n  branch: \"my-feature-branch\"\n\n# OR\n\nknock_client = MyApp.Knock.client(api_key: \"sk_12345\", branch: \"my-feature-branch\")\n```\n\nAlternatively, you can set it as an environment variable:\n\n```bash\nKNOCK_BRANCH=\"my-feature-branch\"\n```\n\n## Usage\n\n### Identifying users\n\n```elixir\nMyApp.Knock.client()\n|\u003e Knock.Users.identify(\"jhammond\", %{\n  \"name\" =\u003e \"John Hammond\",\n  \"email\" =\u003e \"jhammond@ingen.net\",\n})\n```\n\n### Retrieving users\n\n```elixir\nMyApp.Knock.client()\n|\u003e Knock.Users.get_user(\"jhammond\")\n```\n\n### Sending notifies\n\n```elixir\nMyApp.Knock.client()\n|\u003e Knock.Workflows.trigger(\"dinosaurs-loose\", %{\n  # user id of who performed the action\n  \"actor\" =\u003e \"dnedry\",\n  # list of user ids for who should receive the notif\n  \"recipients\" =\u003e [\"jhammond\", \"agrant\", \"imalcolm\", \"esattler\"],\n  # an optional cancellation key\n  \"cancellation_key\" =\u003e alert.id,\n  # an optional tenant\n  \"tenant\" =\u003e \"jurassic-park\",\n  # data payload to send through\n  \"data\" =\u003e %{\n    \"type\" =\u003e \"trex\",\n    \"priority\" =\u003e 1,\n  },\n})\n```\n\n### User preferences\n\n```elixir\nclient = MyApp.Knock.client()\n\n# Set preference set for user\nKnock.Users.set_preferences(client, \"jhammond\", %{channel_types: %{email: true}})\n\n# Set granular channel type preferences\nKnock.Users.set_channel_type_preferences(client, \"jhammond\", :email, true)\n\n# Set granular workflow preferences\nKnock.Users.set_workflow_preferences(client, \"jhammond\", \"dinosaurs-loose\", %{\n  channel_types: %{email: true}\n})\n\n# Retrieve preferences\nKnock.Users.get_preferences(client, \"jhammond\")\n```\n\n### Getting and setting channel data\n\n```elixir\nclient = MyApp.Knock.client()\n\n# Set channel data for an APNS\nKnock.Users.set_channel_data(client, \"jhammond\", KNOCK_APNS_CHANNEL_ID, %{\n  tokens: [apns_token],\n})\n\n# Get channel data for the APNS channel\nKnock.Users.get_channel_data(client, \"jhammond\", KNOCK_APNS_CHANNEL_ID)\n```\n\n### Canceling notifies\n\n```elixir\nMyApp.Knock.client()\n|\u003e Knock.Workflows.cancel(\"dinosaurs-loose\", alert.id, %{\n  # optional list of user ids for who should have their notify canceled\n  \"recipients\" =\u003e [\"jhammond\", \"agrant\", \"imalcolm\", \"esattler\"],\n})\n```\n\n### Signing JWTs\n\nYou can use the excellent `joken` package to [sign JWTs easily](https://hexdocs.pm/joken/asymmetric_cryptography_signers.html#using-asymmetric-algorithms).\nYou will need to generate an environment specific signing key, which you can find in the Knock dashboard.\n\nIf you're using a signing token you will need to pass this to your client to perform authentication.\nYou can read more about [clientside authentication here](https://docs.knock.app/client-integration/authenticating-users).\n\n```elixir\npriv = System.get_env(\"KNOCK_SIGNING_KEY\")\nnow = DateTime.utc_now()\n\nclaims = %{\n  # The user id to sign this key for\n  \"sub\" =\u003e user_id,\n  # When the token was issued\n  \"iat\" =\u003e DateTime.to_unix(now),\n  # When the token expires (1 hour)\n  \"exp\" =\u003e DateTime.add(now, 3600, :second) |\u003e DateTime.to_unix()\n}\n\n\nsigner = Joken.Signer.create(\"RS256\", %{\"pem\" =\u003e priv})\n{:ok, token, _} = Joken.generate_and_sign(%{}, claims, signer)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknocklabs%2Fknock-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknocklabs%2Fknock-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknocklabs%2Fknock-elixir/lists"}