@@ -257,6 +257,70 @@ bot.onMention = async (session, message) => {
257257> while others like Mastodon might implement quotes differently or not support
258258> them at all.
259259
260+ ### Polls
261+
262+ * This API is available since BotKit 0.3.0.*
263+
264+ You can attach a poll to a message by providing
265+ the ` ~SessionPublishOptionsWithQuestion.poll ` option along with
266+ the message class ` Question ` . The poll option allows users to vote on
267+ different choices. For example:
268+
269+ ~~~~ typescript twoslash
270+ import { type Session , Question , text } from " @fedify/botkit" ;
271+ import { Temporal } from " @js-temporal/polyfill" ;
272+ const session = {} as unknown as Session <void >;
273+ // ---cut-before---
274+ await session .publish (text ` What's your favorite color? ` , {
275+ class: Question ,
276+ poll: {
277+ multiple: false , // Single choice poll
278+ options: [" Red" , " Blue" , " Green" ],
279+ endTime: Temporal .Now .instant ().add ({ hours: 24 }),
280+ },
281+ });
282+ ~~~~
283+
284+ For multiple choice polls, set ` ~Poll.multiple ` to ` true ` :
285+
286+ ~~~~ typescript twoslash
287+ import { type Session , Question , text } from " @fedify/botkit" ;
288+ import { Temporal } from " @js-temporal/polyfill" ;
289+ const session = {} as unknown as Session <void >;
290+ // ---cut-before---
291+ await session .publish (text ` Which programming languages do you know? ` , {
292+ class: Question ,
293+ poll: {
294+ multiple: true , // Multiple choice poll
295+ options: [" JavaScript" , " TypeScript" , " Python" , " Rust" ],
296+ endTime: Temporal .Now .instant ().add ({ hours: 24 * 7 }),
297+ },
298+ });
299+ ~~~~
300+
301+ The poll configuration includes:
302+
303+ ` ~Poll.multiple `
304+ : Whether the poll allows multiple selections (` true ` for multiple
305+ choice, ` false ` for single choice).
306+
307+ ` ~Poll.options `
308+ : An array of strings representing the poll options. Each option
309+ must be unique and non-empty.
310+
311+ ` ~Poll.endTime `
312+ : A [ ` Temporal.Instant ` ] representing when the poll closes.
313+
314+ > [ !NOTE]
315+ > Polls are represented as ActivityPub ` Question ` objects. Not all ActivityPub
316+ > implementations support polls, and the behavior may vary between different
317+ > platforms.
318+
319+ > [ !TIP]
320+ > When someone votes on your bot's poll, the ` ~Bot.onVote ` event handler will
321+ > be called. See the [ * Vote* section] ( ./events.md#vote ) in the * Events* concept
322+ > document for more information.
323+
260324
261325Extracting information from a message
262326-------------------------------------
0 commit comments