diff --git a/.changeset/red-wasps-turn.md b/.changeset/red-wasps-turn.md new file mode 100644 index 0000000..602a60e --- /dev/null +++ b/.changeset/red-wasps-turn.md @@ -0,0 +1,5 @@ +--- +"@great-detail/whatsapp": patch +--- + +Offload authentication to use-case diff --git a/src/Client.ts b/src/Client.ts index 81d6a8a..7a13cdc 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -12,7 +12,6 @@ import Webhook from "./Webhook/index.js"; import type { Options as KyOptions } from "ky"; export interface Options { - accessToken?: string; prefixUrl?: string; graphVersion?: `v${string}` | (string & NonNullable); } @@ -25,21 +24,11 @@ export default class Client { public webhook: Webhook; constructor({ - accessToken = process.env.WHATSAPP_ACCESS_TOKEN, prefixUrl = "https://graph.facebook.com", graphVersion = "v20.0", }: Options = {}) { - if (!accessToken) { - throw new Error( - "No access token set in process.env.WHATSAPP_ACCESS_TOKEN", - ); - } - this._request = { prefixUrl: prefixUrl.replace(/\/$/, "") + graphVersion, - headers: { - Authorization: "Bearer " + accessToken, - }, }; this.message = new Message(this._request);