feat: Add WhatsApp poll support (#248)
Implements issue #123 - WhatsApp Poll Support ## Gateway Protocol - Add `poll` RPC method with params: to, question, options (2-12), selectableCount ## ActiveWebListener - Add `sendPoll(to, poll)` method to interface - Implementation uses Baileys poll message type ## CLI Command - `clawdbot poll --to <jid> -q <question> -o <opt1> -o <opt2> [-s count]` - Supports --dry-run, --json, --verbose flags - Validates 2-12 options ## Changes - src/gateway/protocol/schema.ts: Add PollParamsSchema - src/gateway/protocol/index.ts: Export validator and types - src/web/active-listener.ts: Add sendPoll to interface - src/web/inbound.ts: Implement sendPoll using Baileys - src/web/outbound.ts: Add sendPollWhatsApp function - src/gateway/server-methods/send.ts: Add poll handler - src/commands/poll.ts: New CLI command - src/cli/program.ts: Register poll command Closes #123
This commit is contained in:
@@ -5,6 +5,7 @@ import { configureCommand } from "../commands/configure.js";
|
||||
import { doctorCommand } from "../commands/doctor.js";
|
||||
import { healthCommand } from "../commands/health.js";
|
||||
import { onboardCommand } from "../commands/onboard.js";
|
||||
import { pollCommand } from "../commands/poll.js";
|
||||
import { sendCommand } from "../commands/send.js";
|
||||
import { sessionsCommand } from "../commands/sessions.js";
|
||||
import { setupCommand } from "../commands/setup.js";
|
||||
@@ -385,6 +386,58 @@ Examples:
|
||||
}
|
||||
});
|
||||
|
||||
program
|
||||
.command("poll")
|
||||
.description("Create a WhatsApp poll in a chat or group")
|
||||
.requiredOption(
|
||||
"-t, --to <jid>",
|
||||
"Recipient JID (e.g. +15555550123 or group JID)",
|
||||
)
|
||||
.requiredOption("-q, --question <text>", "Poll question")
|
||||
.requiredOption(
|
||||
"-o, --option <choice>",
|
||||
"Poll option (use multiple times, 2-12 required)",
|
||||
(value: string, previous: string[]) => previous.concat([value]),
|
||||
[] as string[],
|
||||
)
|
||||
.option(
|
||||
"-s, --selectable-count <n>",
|
||||
"How many options can be selected (default: 1)",
|
||||
"1",
|
||||
)
|
||||
.option("--dry-run", "Print payload and skip sending", false)
|
||||
.option("--json", "Output result as JSON", false)
|
||||
.option("--verbose", "Verbose logging", false)
|
||||
.addHelpText(
|
||||
"after",
|
||||
`
|
||||
Examples:
|
||||
clawdbot poll --to +15555550123 -q "Lunch today?" -o "Yes" -o "No" -o "Maybe"
|
||||
clawdbot poll --to 123456789@g.us -q "Meeting time?" -o "10am" -o "2pm" -o "4pm" -s 2
|
||||
clawdbot poll --to +15555550123 -q "Favorite color?" -o "Red" -o "Blue" --json`,
|
||||
)
|
||||
.action(async (opts) => {
|
||||
setVerbose(Boolean(opts.verbose));
|
||||
const deps = createDefaultDeps();
|
||||
try {
|
||||
await pollCommand(
|
||||
{
|
||||
to: opts.to,
|
||||
question: opts.question,
|
||||
options: opts.option,
|
||||
selectableCount: Number.parseInt(opts.selectableCount, 10) || 1,
|
||||
json: opts.json,
|
||||
dryRun: opts.dryRun,
|
||||
},
|
||||
deps,
|
||||
defaultRuntime,
|
||||
);
|
||||
} catch (err) {
|
||||
defaultRuntime.error(String(err));
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
program
|
||||
.command("agent")
|
||||
.description("Run an agent turn via the Gateway (use --local for embedded)")
|
||||
|
||||
Reference in New Issue
Block a user