From dfaf6ebffb63820589b06269f22946db0f8acee3 Mon Sep 17 00:00:00 2001 From: Dom Webber Date: Wed, 20 Nov 2024 20:34:28 +0000 Subject: [PATCH] Add message text CLI command --- .changeset/shaggy-knives-applaud.md | 5 +++++ README.md | 2 +- src/cli.ts | 24 +++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 .changeset/shaggy-knives-applaud.md diff --git a/.changeset/shaggy-knives-applaud.md b/.changeset/shaggy-knives-applaud.md new file mode 100644 index 00000000..7775d657 --- /dev/null +++ b/.changeset/shaggy-knives-applaud.md @@ -0,0 +1,5 @@ +--- +"@great-detail/whatsapp": patch +--- + +Add CLI command: message text diff --git a/README.md b/README.md index d937332f..e2368a9d 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ export WHATSAPP_PHONE_NUMBER_ID="" # Send a Text Message # TODO: Re-add with updated SDK -# npx @great-detail/whatsapp message send text "" --body="Hello, World!" +npx @great-detail/whatsapp message send text "" --body="Hello, World!" # Note: may be a Phone Number ID - it may not always be the phone number itself. # Send an Image Message diff --git a/src/cli.ts b/src/cli.ts index 669f0337..2141b576 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -10,7 +10,8 @@ */ import { program } from "commander"; import getStdin from "get-stdin"; -import Client from "./index.js"; +import Client from "./Client.js"; +import { MessageType } from "./types/Message/index.js"; const WHATSAPP_ACCESS_TOKEN = process.env.WHATSAPP_ACCESS_TOKEN; const WHATSAPP_PHONE_NUMBER_ID = process.env.WHATSAPP_PHONE_NUMBER_ID; @@ -107,4 +108,25 @@ mediaCommand console.log(await result.json()); }); +const messageCommand = program.command("message").description("Message"); + +messageCommand + .command("text") + .description("Send a Text message") + .argument("", "Message recipient Phone Number or Phone Number ID") + .requiredOption("--body ", "Message body") + .option("--preview-url", "Enable URL previewing for the message") + .action(async (recipient, options) => { + const result = await sdk.message.createMessage({ + to: recipient, + phoneNumberID: options.phoneNumberId, + type: MessageType.Text, + [MessageType.Text]: { + body: options.body, + preview_url: options.previewUrl, + }, + }); + console.log(await result.json()); + }); + program.parseAsync();