使用 OpenClaw 建立互動式投票:支援 WhatsApp、Discord 與 Teams
在開發機器人或自動化流程時,最煩人的工作之一就是處理跨平台的互動功能。如果你想在不同的通訊軟體發起投票,通常得去翻遍各家的 API 文件,處理完全不同的資料格式,這對開發者來說非常耗時。
OpenClaw 簡化了這個過程,讓你用統一的介面就能在多個頻道發起投票。不管是簡單的午餐調查還是複雜的團隊決策,你都不需要為每個平台重新寫一套邏輯。
- WhatsApp (web channel)
- Discord
- MS Teams (Adaptive Cards)
# WhatsAppopenclaw message poll --target +15555550123 \ --poll-question "Lunch today?" --poll-option "Yes" --poll-option "No" --poll-option "Maybe"openclaw message poll --target 123456789@g.us \ --poll-question "Meeting time?" --poll-option "10am" --poll-option "2pm" --poll-option "4pm" --poll-multi
# Discordopenclaw message poll --channel discord --target channel:123456789 \ --poll-question "Snack?" --poll-option "Pizza" --poll-option "Sushi"openclaw message poll --channel discord --target channel:123456789 \ --poll-question "Plan?" --poll-option "A" --poll-option "B" --poll-duration-hours 48
# MS Teamsopenclaw message poll --channel msteams --target conversation:19:abc@thread.tacv2 \ --poll-question "Lunch?" --poll-option "Pizza" --poll-option "Sushi"選項:
--channel:whatsapp(預設),discord, 或msteams--poll-multi: 允許選擇多個選項--poll-duration-hours: 僅限 Discord (省略時預設為 24)
Gateway RPC
Section titled “Gateway RPC”方法:poll
參數:
to(string, 必填)question(string, 必填)options(string[], 必填)maxSelections(number, 選填)durationHours(number, 選填)channel(string, 選填, 預設:whatsapp)idempotencyKey(string, 必填)
- WhatsApp: 支援 2-12 個選項,
maxSelections必須在選項數量範圍內,會忽略durationHours。 - Discord: 支援 2-10 個選項,
durationHours限制在 1-768 小時(預設 24)。當maxSelections > 1時會啟用多選模式;Discord 不支援嚴格的選取數量限制。 - MS Teams: 使用 Adaptive Card 投票(由 OpenClaw 管理)。由於沒有原生投票 API,
durationHours會被忽略。
Agent 工具 (Message)
Section titled “Agent 工具 (Message)”使用 message 工具搭配 poll 動作 (to, pollQuestion, pollOption, 選填 pollMulti, pollDurationHours, channel)。
注意:Discord 沒有「精確選擇 N 項」的模式;pollMulti 會對應到多選功能。
Teams 的投票是以 Adaptive Cards 呈現,需要 Gateway 保持在線才能將投票結果記錄在 ~/.openclaw/msteams-polls.json 中。
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。