/// <summary> /// Style a prompt and populate the message based on <see cref="PromptStyler.PromptStyle"/>. /// </summary> /// <typeparam name="T"> The type of the options.</typeparam> /// <param name="message"> The message that will contain the prompt.</param> /// <param name="prompt"> The prompt.</param> /// <param name="options"> The options.</param> /// <remarks> /// <typeparamref name="T"/> should implement <see cref="object.ToString"/>. /// </remarks> public virtual void Apply <T>(ref Message message, string prompt, IList <T> options) { SetField.CheckNull(nameof(prompt), prompt); SetField.CheckNull(nameof(options), options); switch (PromptStyle) { case PromptStyle.Auto: message.Text = prompt; message.AddButtons(options); break; case PromptStyle.AutoText: Apply(ref message, prompt, options, options?.Count() > 4 ? PromptStyle.PerLine : PromptStyle.Inline); break; case PromptStyle.Inline: //TODO: Refactor buildlist function to a more generic namespace when changing prompt to use recognizers. message.Text = $"{prompt} {FormFlow.Advanced.Language.BuildList(options.Select(option => option.ToString()), Resources.DefaultChoiceSeparator, Resources.DefaultChoiceLastSeparator)}"; break; case PromptStyle.PerLine: message.Text = $"{prompt}\n{FormFlow.Advanced.Language.BuildList(options.Select(option => $"* {option.ToString()}"), "\n", "\n")}"; break; case PromptStyle.None: default: message.Text = prompt; break; } }
public PersistentDialogTask(Func <IEventLoop> makeInner, IEventProducer <IActivity> queue, IBotData botData) { SetField.NotNull(out this.botData, nameof(botData), botData); SetField.NotNull(out this.queue, nameof(queue), queue); SetField.CheckNull(nameof(makeInner), makeInner); this.inner = new Lazy <IEventLoop>(() => makeInner()); }
/// <summary> /// Constructs a case based on a regular expression. /// </summary> /// <param name="regex"> The regex for condition.</param> /// <param name="selector"> The contextual selector for the case.</param> public RegexCase(Regex regex, ContextualSelector <string, R> selector) { SetField.CheckNull(nameof(selector), selector); this.Selector = selector; SetField.NotNull(out this.Regex, nameof(regex), regex); this.Condition = this.IsMatch; }
/// <summary> /// Constructs a case. /// </summary> /// <param name="condition"> The condition of the case.</param> /// <param name="selector"> The contextual selector of the case.</param> public Case(Func <T, bool> condition, ContextualSelector <T, R> selector) { SetField.CheckNull(nameof(condition), condition); this.Condition = condition; SetField.CheckNull(nameof(selector), selector); this.Selector = selector; }
public WikiQnAKnowledgeBaseService(string qnaMakerSubscriptionKey, string qnaMakerKnowledgeBaseId) { SetField.NotNull(out this.qnaMakerSubscriptionKey, nameof(qnaMakerSubscriptionKey), qnaMakerSubscriptionKey); SetField.CheckNull(nameof(qnaMakerKnowledgeBaseId), qnaMakerKnowledgeBaseId); this.qnaMakerUri = new Uri(string.Format(QnaMakerBaseUri, qnaMakerKnowledgeBaseId)); }
public DetectEmulatorFactory(Message message, Uri emulator) { SetField.CheckNull(nameof(message), message); var channel = message.From; this.isEmulator = channel?.ChannelId?.Equals("emulator", StringComparison.OrdinalIgnoreCase); SetField.NotNull(out this.emulator, nameof(emulator), emulator); }
/// <summary> /// Creates an instance of the resumption cookie. /// </summary> /// <param name="userId"> The user Id.</param> /// <param name="botId"> The bot Id.</param> /// <param name="conversationId"> The conversation Id.</param> /// <param name="channelId"> The channel Id of the conversation.</param> /// <param name="serviceUrl"> The service url of the conversation.</param> /// <param name="locale"> The locale of the message.</param> public ResumptionCookie(string userId, string botId, string conversationId, string channelId, string serviceUrl, string locale = "en") { // purposefully using named arguments because these all have the same type this.Address = new Address(botId: botId, channelId: channelId, userId: userId, conversationId: conversationId, serviceUrl: serviceUrl); SetField.CheckNull(nameof(locale), locale); this.IsTrustedServiceUrl = MicrosoftAppCredentials.IsTrustedServiceUrl(serviceUrl); this.Locale = locale; }
public PersistentDialogTask(Func <IPostToBot> makeInner, IMessageActivity message, IConnectorClient client, IBotToUser botToUser, IBotData botData) { SetField.NotNull(out this.message, nameof(message), message); SetField.NotNull(out this.client, nameof(client), client); SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser); SetField.NotNull(out this.botData, nameof(botData), botData); SetField.CheckNull(nameof(makeInner), makeInner); this.inner = new Lazy <IPostToBot>(() => makeInner()); }
public ConnectorClientFactory(IMessageActivity message, MicrosoftAppCredentials credentials) { SetField.NotNull(out this.message, nameof(message), message); SetField.NotNull(out this.credentials, nameof(credentials), credentials); SetField.CheckNull(nameof(message.ServiceUrl), message.ServiceUrl); this.serviceUri = new Uri(message.ServiceUrl); this.isEmulator = message.ChannelId?.Equals("emulator", StringComparison.OrdinalIgnoreCase); }
public override void Apply <T>(ref IMessageActivity message, string prompt, IReadOnlyList <T> options, IReadOnlyList <string> descriptions = null, string speak = null) { SetField.CheckNull(nameof(prompt), prompt); SetField.CheckNull(nameof(options), options); message.Speak = speak; message.InputHint = InputHints.ExpectingInput; if (descriptions == null) { descriptions = (from option in options select option.ToString()).ToList(); } switch (PromptStyle) { case PromptStyle.Auto: case PromptStyle.Keyboard: if (options != null && options.Any()) { if (PromptStyle == PromptStyle.Keyboard) { message.SuggestedActions = new SuggestedActions(actions: GenerateButtons(options, descriptions)); message.Text = prompt; } else { var heroCard = new HeroCard(text: prompt, buttons: GenerateButtons(options, descriptions)); message.AttachmentLayout = AttachmentLayoutTypes.Carousel; message.Attachments = new List <Attachment>() { (isAdaptiveCard) ? heroCard.ToAdaptiveCard().ToAttachment() : heroCard.ToAttachment() }; } } else { message.Text = prompt; } break; case PromptStyle.AutoText: Apply(ref message, prompt, options, options?.Count() > 4 ? PromptStyle.PerLine : PromptStyle.Inline, descriptions); break; case PromptStyle.Inline: //TODO: Refactor buildlist function to a more generic namespace when changing prompt to use recognizers. message.Text = $"{prompt} {Microsoft.Bot.Builder.FormFlow.Advanced.Language.BuildList(descriptions, Resources.DefaultChoiceSeparator, Resources.DefaultChoiceLastSeparator)}"; break; case PromptStyle.PerLine: message.Text = $"{prompt}{Environment.NewLine}{Microsoft.Bot.Builder.FormFlow.Advanced.Language.BuildList(descriptions.Select(description => $"* {description}"), Environment.NewLine, Environment.NewLine)}"; break; case PromptStyle.None: default: message.Text = prompt; break; } }
public static BotDataKey GetBotDataKey(this IMessageActivity message, string botId) { SetField.CheckNull(nameof(botId), botId); return(new BotDataKey { BotId = botId, UserId = message.From.Id, ConversationId = message.Conversation.Id, ChannelId = message.ChannelId }); }
/// <summary> /// Creates an instance of the resumption cookie. /// </summary> /// <param name="userId"> The user Id.</param> /// <param name="botId"> The bot Id.</param> /// <param name="conversationId"> The conversation Id.</param> /// <param name="channelId"> The channel Id of the conversation.</param> /// <param name="language"> The language of the message.</param> public ResumptionCookie(string userId, string botId, string conversationId, string channelId, string language = "en") { SetField.CheckNull(nameof(userId), userId); SetField.CheckNull(nameof(botId), botId); SetField.CheckNull(nameof(conversationId), conversationId); SetField.CheckNull(nameof(channelId), channelId); SetField.CheckNull(nameof(language), language); this.UserId = userId; this.BotId = botId; this.ConversationId = conversationId; this.UserChannelId = channelId; this.Language = language; }
public Address(string botId, string channelId, string userId, string conversationId, string serviceUrl) { SetField.CheckNull(nameof(botId), botId); SetField.CheckNull(nameof(channelId), channelId); SetField.CheckNull(nameof(userId), userId); SetField.CheckNull(nameof(conversationId), conversationId); SetField.CheckNull(nameof(serviceUrl), serviceUrl); this.BotId = botId; this.ChannelId = channelId; this.UserId = userId; this.ConversationId = conversationId; this.ServiceUrl = serviceUrl; }
/// <summary> /// Creates an instance of the resumption cookie. /// </summary> /// <param name="userId"> The user Id.</param> /// <param name="botId"> The bot Id.</param> /// <param name="conversationId"> The conversation Id.</param> /// <param name="channelId"> The channel Id of the conversation.</param> /// <param name="serviceUrl"> The service url of the conversation.</param> /// <param name="locale"> The locale of the message.</param> public ResumptionCookie(string userId, string botId, string conversationId, string channelId, string serviceUrl, string locale = "en") : this(new Address( // purposefully using named arguments because these all have the same type botId : botId, channelId : channelId, userId : userId, conversationId : conversationId, serviceUrl : serviceUrl ) ) { SetField.CheckNull(nameof(locale), locale); this.Locale = locale; }
/// <summary> /// Creates an instance of the resumption cookie. /// </summary> /// <param name="userId"> The user Id.</param> /// <param name="botId"> The bot Id.</param> /// <param name="conversationId"> The conversation Id.</param> /// <param name="channelId"> The channel Id of the conversation.</param> /// <param name="serviceUrl"> The service url of the conversation.</param> /// <param name="locale"> The locale of the message.</param> public ResumptionCookie(string userId, string botId, string conversationId, string channelId, string serviceUrl, string locale = "en") { SetField.CheckNull(nameof(userId), userId); SetField.CheckNull(nameof(botId), botId); SetField.CheckNull(nameof(conversationId), conversationId); SetField.CheckNull(nameof(channelId), channelId); SetField.CheckNull(nameof(serviceUrl), serviceUrl); SetField.CheckNull(nameof(locale), locale); this.UserId = userId; this.BotId = botId; this.ConversationId = conversationId; this.ChannelId = channelId; this.ServiceUrl = serviceUrl; this.Locale = locale; }
/// <summary> /// Style a prompt and populate the message based on <see cref="PromptStyler.PromptStyle"/>. /// </summary> /// <typeparam name="T"> The type of the options.</typeparam> /// <param name="message"> The message that will contain the prompt.</param> /// <param name="prompt"> The prompt.</param> /// <param name="options"> The options.</param> /// <param name="descriptions">Descriptions to display for each option.</param> /// <remarks> /// <typeparamref name="T"/> should implement <see cref="object.ToString"/> unless descriptions are supplied. /// </remarks> public virtual void Apply <T>(ref IMessageActivity message, string prompt, IReadOnlyList <T> options, IReadOnlyList <string> descriptions = null) { SetField.CheckNull(nameof(prompt), prompt); SetField.CheckNull(nameof(options), options); if (descriptions == null) { descriptions = (from option in options select option.ToString()).ToList(); } switch (PromptStyle) { case PromptStyle.Auto: case PromptStyle.Keyboard: if (options != null && options.Any()) { if (PromptStyle == PromptStyle.Keyboard) { message.AddKeyboardCard(prompt, options, descriptions); } else { message.AddHeroCard(prompt, options, descriptions); } } else { message.Text = prompt; } break; case PromptStyle.AutoText: Apply(ref message, prompt, options, options?.Count() > 4 ? PromptStyle.PerLine : PromptStyle.Inline, descriptions); break; case PromptStyle.Inline: //TODO: Refactor buildlist function to a more generic namespace when changing prompt to use recognizers. message.Text = $"{prompt} {FormFlow.Advanced.Language.BuildList(descriptions, Resources.DefaultChoiceSeparator, Resources.DefaultChoiceLastSeparator)}"; break; case PromptStyle.PerLine: message.Text = $"{prompt}\n{FormFlow.Advanced.Language.BuildList(descriptions.Select(description => $"* {description}"), "\n", "\n")}"; break; case PromptStyle.None: default: message.Text = prompt; break; } }
public BotDataBase(IBotIdResolver botIdResolver, IMessageActivity message, IBotDataStore botDataStore) { SetField.NotNull(out this.botDataStore, nameof(BotDataBase <T> .botDataStore), botDataStore); SetField.CheckNull(nameof(message), message); this.botDataKey = message.GetBotDataKey(botIdResolver.BotId); }
public BotDataBase(Message message, IBotDataStore botDataStore) { SetField.NotNull(out this.botDataStore, nameof(BotDataBase <T> .botDataStore), botDataStore); SetField.CheckNull(nameof(message), message); this.botDataKey = message.GetBotDataKey(); }
public DetectChannelCapability(Message message) { SetField.CheckNull(nameof(message), message); SetField.NotNull(out channel, nameof(channel), message.From); }
/// <summary> /// Constructs a choice dialog. /// </summary> /// <param name="promptOptions"> The prompt options</param> public PromptChoice(PromptOptions <T> promptOptions) : base(promptOptions) { SetField.CheckNull(nameof(promptOptions.Options), promptOptions.Options); }
public PersistentDialogTask(Func <IPostToBot> makeInner, IBotData botData) { SetField.NotNull(out this.botData, nameof(botData), botData); SetField.CheckNull(nameof(makeInner), makeInner); this.inner = new Lazy <IPostToBot>(() => makeInner()); }
/// <summary> /// Style a prompt and populate the <see cref="Message.Text"/>. /// </summary> /// <param name="message"> The message that will contain the prompt.</param> /// <param name="prompt"> The prompt.</param> public virtual void Apply(ref Message message, string prompt) { SetField.CheckNull(nameof(prompt), prompt); message.Text = prompt; }
public ResumptionContext(Func <IBotDataBag> makeBotDataBag) { SetField.CheckNull(nameof(makeBotDataBag), makeBotDataBag); this.botDataBag = new Lazy <IBotDataBag>(() => makeBotDataBag()); }
public DetectChannelCapability(IMessageActivity message) { SetField.CheckNull(nameof(message), message); SetField.NotNull(out channelId, nameof(channelId), message.ChannelId); SetField.NotNull(out serviceUrl, nameof(serviceUrl), message.ServiceUrl); }