diff --git a/.changeset/shaggy-knives-applaud.md b/.changeset/shaggy-knives-applaud.md new file mode 100644 index 0000000..7775d65 --- /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 d937332..e2368a9 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 669f033..2141b57 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();