다음을 통해 공유


ChoiceFactory class

선택 항목 목록이 포함된 '메시지' 작업의 서식을 지정하는 데 도움이 되는 유틸리티 함수 집합입니다.

설명

이 예제에서는 기본 채널의 기능에 따라 조건부로 서식이 지정된 선택 항목 목록이 포함된 메시지를 만드는 방법을 보여 줍니다.

const { ChoiceFactory } = require('botbuilder-choices');

const message = ChoiceFactory.forChannel(context, ['red', 'green', 'blue'], `Pick a color.`);
await context.sendActivity(message);

메서드

forChannel(string | TurnContext, string | Choice[], string, string, ChoiceFactoryOptions)

지정된 채널의 기능에 따라 자동으로 서식이 지정된 선택 항목 목록이 포함된 '메시지' 활동을 반환합니다.

heroCard(string | Choice[], string, string)

HeroCard's로 추가된 선택 목록을 포함하는 메시지 활동 만듭니다.

inline(string | Choice[], string, string, ChoiceFactoryOptions)

인라인 목록으로 서식이 지정된 선택 항목 목록이 포함된 '메시지' 활동을 반환합니다.

list(string | Choice[], string, string, ChoiceFactoryOptions)

번호 매기기 또는 글머리 기호 목록으로 서식이 지정된 선택 항목 목록을 포함하는 '메시지' 활동을 반환합니다.

suggestedAction(string | Choice[], string, string)

제안된 작업으로 추가된 선택 항목 목록이 포함된 '메시지' 활동을 반환합니다.

toChoices(string | Choice[] | undefined)

stringChoice 기반 선택 항목의 혼합 목록을 사용하여 Choice[]반환합니다.

메서드 세부 정보

forChannel(string | TurnContext, string | Choice[], string, string, ChoiceFactoryOptions)

지정된 채널의 기능에 따라 자동으로 서식이 지정된 선택 항목 목록이 포함된 '메시지' 활동을 반환합니다.

static function forChannel(channelOrContext: string | TurnContext, choices: string | Choice[], text?: string, speak?: string, options?: ChoiceFactoryOptions): Partial<Activity>

매개 변수

channelOrContext

string | TurnContext

현재 대화 전환에 대한 채널 ID 또는 컨텍스트 개체입니다.

choices

string | Choice[]

렌더링할 선택 항목 목록입니다.

text

string

(선택 사항) 메시지의 텍스트입니다.

speak

string

(선택 사항) 메시지를 말할 SSML입니다.

options
ChoiceFactoryOptions

(선택 사항) 목록으로 렌더링할 때 사용할 서식 옵션입니다.

반환

Partial<Activity>

만든 메시지 활동입니다.

설명

알고리즘은 제공된 선택 목록의 서식을 제안된 작업으로 지정하는 것을 선호하지만 제안된 작업이 채널에서 기본적으로 지원되지 않거나, 채널에 표시할 선택 항목이 너무 많거나, 선택한 제목이 너무 긴 경우 텍스트 기반 목록을 사용하도록 결정할 수 있습니다.

알고리즘이 목록을 사용하기로 결정한 경우 선택 항목이 3개 이하이고 모두 짧은 제목이 있는 경우 인라인 목록을 사용합니다. 그렇지 않으면 번호 매기기 목록이 사용됩니다.

const message = ChoiceFactory.forChannel(context, [
   { value: 'red', action: { type: 'imBack', title: 'The Red Pill', value: 'red pill' } },
   { value: 'blue', action: { type: 'imBack', title: 'The Blue Pill', value: 'blue pill' } },
], `Which do you choose?`);
await context.sendActivity(message);

heroCard(string | Choice[], string, string)

HeroCard's로 추가된 선택 목록을 포함하는 메시지 활동 만듭니다.

static function heroCard(choices?: string | Choice[], text?: string, speak?: string): Activity

매개 변수

choices

string | Choice[]

선택적. 추가할 선택 목록입니다.

text

string

선택적. 메시지의 텍스트입니다.

speak

string

선택적. 음성 지원 채널에서 봇이 말하는 SSML 텍스트입니다.

반환

Activity

단추가 있는 HeroCard 선택 항목이 있는 활동.

inline(string | Choice[], string, string, ChoiceFactoryOptions)

인라인 목록으로 서식이 지정된 선택 항목 목록이 포함된 '메시지' 활동을 반환합니다.

static function inline(choices: string | Choice[], text?: string, speak?: string, options?: ChoiceFactoryOptions): Partial<Activity>

매개 변수

choices

string | Choice[]

렌더링할 선택 항목 목록입니다.

text

string

(선택 사항) 메시지의 텍스트입니다.

speak

string

(선택 사항) 메시지를 말할 SSML입니다.

options
ChoiceFactoryOptions

(선택 사항) 목록 렌더링을 조정하는 서식 옵션입니다.

반환

Partial<Activity>

만든 메시지 활동입니다.

설명

이 예제에서는 "색 선택: (1. 빨간색, 2. 녹색 또는 3. 파란색)"의 메시지 텍스트를 생성합니다.

const message = ChoiceFactory.inline(['red', 'green', 'blue'], `Pick a color:`);
await context.sendActivity(message);

list(string | Choice[], string, string, ChoiceFactoryOptions)

번호 매기기 또는 글머리 기호 목록으로 서식이 지정된 선택 항목 목록을 포함하는 '메시지' 활동을 반환합니다.

static function list(choices: string | Choice[], text?: string, speak?: string, options?: ChoiceFactoryOptions): Partial<Activity>

매개 변수

choices

string | Choice[]

렌더링할 선택 항목 목록입니다.

text

string

(선택 사항) 메시지의 텍스트입니다.

speak

string

(선택 사항) 메시지를 말할 SSML입니다.

options
ChoiceFactoryOptions

(선택 사항) 목록 렌더링을 조정하는 서식 옵션입니다.

반환

Partial<Activity>

만든 메시지 활동입니다.

설명

이 예제에서는 번호 매기기 목록으로 표시되는 선택 항목이 포함된 메시지를 생성합니다.

const message = ChoiceFactory.list(['red', 'green', 'blue'], `Pick a color:`);
await context.sendActivity(message);

suggestedAction(string | Choice[], string, string)

제안된 작업으로 추가된 선택 항목 목록이 포함된 '메시지' 활동을 반환합니다.

static function suggestedAction(choices: string | Choice[], text?: string, speak?: string): Partial<Activity>

매개 변수

choices

string | Choice[]

추가할 선택 항목 목록입니다.

text

string

(선택 사항) 메시지의 텍스트입니다.

speak

string

(선택 사항) 메시지를 말할 SSML입니다.

반환

Partial<Activity>

제안된 작업으로 선택 항목이 있는 활동입니다.

설명

이 예제에서는 제안된 작업 단추로 제공되는 선택 항목이 포함된 메시지를 생성합니다.

const message = ChoiceFactory.suggestedAction(['red', 'green', 'blue'], `Pick a color:`);
await context.sendActivity(message);

toChoices(string | Choice[] | undefined)

stringChoice 기반 선택 항목의 혼합 목록을 사용하여 Choice[]반환합니다.

static function toChoices(choices: string | Choice[] | undefined): Choice[]

매개 변수

choices

string | Choice[] | undefined

추가할 선택 항목 목록입니다.

반환

Choice[]

선택 항목 목록입니다.

설명

다음은 문자열 기반 선택 항목의 간단한 배열을 올바른 형식의 Choice[]변환하는 예제입니다.

Choice Choice.action대한 Partial<CardAction> 있는 경우 .toChoices()Choice.action채우려고 시도합니다.

const choices = ChoiceFactory.toChoices(['red', 'green', 'blue']);