/// <summary> /// Post a message to be sent to the bot, using previous messages to establish a conversation context. /// </summary> /// <param name="text">The message text.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A task that represents the post operation.</returns> public static async Task PostAsync(this IBotToUser botToUser, string text, CancellationToken cancellationToken = default(CancellationToken)) { var message = botToUser.MakeMessage(); message.Text = text; await botToUser.PostAsync(message, cancellationToken); }
private static async Task SendMessageAsync(IBotToUser context, Attachment attachment) { var message = context.MakeMessage(); message.Attachments.Add(attachment); await context.PostAsync(message); }
public DialogContextFactory(IDialogContextStore store, IFrameFactory frames, IBotToUser botToUser, IBotData botData) { SetField.NotNull(out this.store, nameof(store), store); SetField.NotNull(out this.frames, nameof(frames), frames); SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser); SetField.NotNull(out this.botData, nameof(botData), botData); }
async Task IAlarmRenderer.RenderAsync(IBotToUser botToUser, string title, DateTime now) { Alarm alarm; if (this.scheduler.TryFindAlarm(title, out alarm)) { var card = new HeroCard(); card.Title = alarm.Title ?? "Default Alarm"; card.Subtitle = alarm.State ? (alarm.When.HasValue ? $"{alarm.When}" : "not set") : "disabled"; IAlarmable query = alarm; DateTime next; if (query.TryFindNext(now, out next)) { var remaining = next.Subtract(now); bool today = now.Date == next.Date; card.Text = $"There is {remaining:dd\\.hh\\:mm\\:ss} remaining before this alarm rings."; } var buttons = this.actions.ActionsFor(alarm); card.Buttons = buttons.ToArray(); var message = botToUser.MakeMessage(); message.Attachments = new[] { card.ToAttachment() }; await botToUser.PostAsync(message); } else { throw new AlarmNotFoundException(); } }
/// <summary> /// Posts a typing (e.g. "...") message to user. /// </summary> public static Task PostTyping(this IBotToUser context) { var reply = context.MakeMessage(); reply.Type = ActivityTypes.Typing; return(context.PostAsync(reply)); }
public DeleteProfileScorable(IDialogStack stack, IBotData botData, IBotToUser botToUser, Regex regex) { SetField.NotNull(out this.stack, nameof(stack), stack); SetField.NotNull(out this.botData, nameof(botData), botData); SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser); SetField.NotNull(out this.regex, nameof(regex), regex); }
/// <summary> /// Initialize authentication scorable. /// </summary> /// <param name="botdata">Bot data</param> /// <param name="dialogTask">Dialog task</param> /// <param name="botToUser">Bot to user</param> /// <param name="resourceId">Azure active directory resource identifier.</param> public AuthenticationScorable(IBotData botdata, IDialogTask dialogTask, IBotToUser botToUser, AuthenticationOptions authOptions, IAuthProvider authProvider) { _botData = botdata; _dialogTask = dialogTask; this.authOptions = authOptions; this.authProvider = authProvider; }
public DialogContext(IBotToUser botToUser, IBotData botData, IDialogStack stack, CancellationToken token) { SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser); SetField.NotNull(out this.botData, nameof(botData), botData); SetField.NotNull(out this.stack, nameof(stack), stack); this.token = token; }
async Task IMessageQueue.DrainQueueAsync(IBotToUser botToUser, CancellationToken token) { while (this.queue.Count > 0) { var toUser = this.queue.Dequeue(); // last message in the queue will be treated specially for channels that need input hints if (this.queue.Count == 0) { var stack = this.makeStack(); if (this.channelCapability.ShouldSetInputHint(toUser) && stack.Frames.Count > 0) { var topOfStack = stack.Frames[0].Target; // if there is a prompt dialog on top of stack, the InputHint will be set to Expecting if (topOfStack != null && topOfStack.GetType().DeclaringType == typeof(PromptDialog)) { toUser.InputHint = InputHints.ExpectingInput; } else { toUser.InputHint = InputHints.AcceptingInput; } } } else { if (this.channelCapability.ShouldSetInputHint(toUser)) { toUser.InputHint = InputHints.IgnoringInput; } } await botToUser.PostAsync(toUser, token); } }
public PostUnhandledExceptionToUser(IPostToBot inner, IBotToUser botToUser, ResourceManager resources, TraceListener trace) { SetField.NotNull(out this.inner, nameof(inner), inner); SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser); SetField.NotNull(out this.resources, nameof(resources), resources); SetField.NotNull(out this.trace, nameof(trace), trace); }
private static async Task SendMessageAsync(IBotToUser context, string text) { var message = context.MakeMessage(); message.Text = text; await context.PostAsync(message); }
public DeleteProfileScorable(IDialogStack stack, IBotData botData, IBotToUser botToUser, Func <IDialog <object> > makeroot) { SetField.NotNull(out this.stack, nameof(stack), stack); SetField.NotNull(out this.botData, nameof(botData), botData); SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser); SetField.NotNull(out this.makeroot, nameof(makeroot), makeroot); }
public BotDialogContextArgs(IActivity activity, IDialogTask task, IBotData data, IBotToUser botToUser, ILifetimeScope scope) { Activity = activity; Task = task; BotData = data; DialogScope = scope; BotToUser = botToUser; }
/// <summary> /// Constructor. /// </summary> /// <param name="botToUser">Where to replay transcript.</param> /// <param name="header">Function for defining the transcript header on each message.</param> public ReplayTranscript(IBotToUser botToUser, Func <IActivity, string> header = null) { _botToUser = botToUser; if (_header == null) { _header = (activity) => $"({activity.From.Name} {activity.Timestamp:g})"; } }
public UserToBotFilter(IPostToBot inner, IBotToUser botToUser, ResourceManager resources, TraceListener trace) { this.messageProvider = (IMessageProvider)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IMessageProvider)); SetField.NotNull(out this.inner, nameof(inner), inner); SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser); SetField.NotNull(out this.resources, nameof(resources), resources); SetField.NotNull(out this.trace, nameof(trace), trace); }
private static async Task EvaluateAndRespondToSentimentAsync(IBotToUser context, Sentiment sentiment, string languageCode) { // If there's no Sentiment object or score value, quit now. if (sentiment?.Score == null) { return; } var sentimentResponse = string.Empty; try { // Score ranges from 0.0 to 1, with 4 decimals of precision if (sentiment.Score <= 0.1) { // If the sentiment is lower than 3%, respond with apologies and recommend to reach out to support sentimentResponse = "I'm sorry you're having problems. If you'd like to talk to a person, please email [email protected] and they will be able to assist further."; } else if (sentiment.Score >= 0.95) { // if the sentiment is in the top 97%, respond with a reminder to leave a review for the app. sentimentResponse = "I'm happy to see you're enjoying our services. Please consider leaving an app review after you're done today!"; } // If there's no response needed, quit now. if (string.IsNullOrEmpty(sentimentResponse)) { return; } // Check to see if we need to translate the response. if (languageCode != "en") { using (var translationClient = new TextTranslationServiceClient(SubscriptionKeys.TextTranslationServiceKey)) { if (!string.IsNullOrEmpty(sentimentResponse)) { var translationResult = await translationClient.TranslateAsync(sentimentResponse, languageCode); var translatedSentimentResponse = translationResult.Translations.FirstOrDefault()?.Text; if (!string.IsNullOrEmpty(translatedSentimentResponse)) { // If we were able to translate the message, update the message we're sending. sentimentResponse = translatedSentimentResponse; } } } } // Reply with the sentiment response. await context.PostAsync(sentimentResponse); } catch (Exception ex) { await context.PostAsync($"EvaluateAndRespondToSentimentAsync Exception: {ex.Message}"); } }
private static async Task ShowHelp(IBotToUser context) { await context.PostAsync("You can ask me about talks, rooms and speakers.\n\n" + "Try asking: When is Tatham's talk?\n\n" + "or\n\n" + "What's happening on Red room?\n\n" + "or\n\n" + "What's going on at 3PM?"); }
/// <summary> /// Initializes a new instance of the <see cref="ResetScorable"/> class. /// </summary> public ResetScorable(IDialogFactory dialogFactory, IDialogStack stack, IBotToUser botToUser, IBotData botData, IDialogTask task) : base(Resources.ResetScorable_Match) { SetField.NotNull(out _task, nameof(task), task); SetField.NotNull(out _botData, nameof(botData), botData); SetField.NotNull(out _stack, nameof(stack), stack); SetField.NotNull(out _dialogFactory, nameof(dialogFactory), dialogFactory); SetField.NotNull(out _botToUser, nameof(botToUser), botToUser); }
private static async Task SendMessageAsync(IBotToUser context, List <HeroCard> cards, string title) { var message = context.MakeMessage(); message.Text = title; message.AttachmentLayout = AttachmentLayoutTypes.Carousel; message.Attachments = cards.Select(card => card.ToAttachment()).ToList(); await context.PostAsync(message); }
private IMessageActivity BuildIntroMessageForSms(IBotToUser context) { var message = context.MakeMessage(); message.Text = "Hello, I am Expert Intelligence Bot. I'll collect some information to get started, " + "then a human project manager will review your request and follow up. \n\n\n\n" + "Would you like web research?\n\n\n\n" + "You can say: 'yes' or 'no'"; message.TextFormat = "plain"; return(message); }
public static async Task <DialogContext> MakeContextAsync(IDialog root, IBotToUser botToUser) { var data = new JObjectBotData(new Connector.Message()); IFiberLoop fiber = new Fiber(new FrameFactory(new WaitFactory())); var context = new DialogContext(botToUser, data, fiber); var loop = Methods.Void(Methods.Loop(context.ToRest(root.StartAsync), int.MaxValue)); fiber.Call(loop, null); await fiber.PollAsync(); return(context); }
/// <summary> /// Post a message to be sent to the bot, using previous messages to establish a conversation context. /// </summary> /// <remarks> /// If the locale parameter is not set, locale of the incoming message will be used for reply. /// </remarks> /// <param name="botToUser">Communication channel to use.</param> /// <param name="text">The message text.</param> /// <param name="locale">The locale of the text.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A task that represents the post operation.</returns> public static async Task PostAsync(this IBotToUser botToUser, string text, string locale = null, CancellationToken cancellationToken = default(CancellationToken)) { var message = botToUser.MakeMessage(); message.Text = text; if (!string.IsNullOrEmpty(locale)) { message.Locale = locale; } await botToUser.PostAsync(message, cancellationToken); }
private static IMessageActivity GetOptionsMessage(IBotToUser context) { var message = context.MakeMessage(); var buttons = GetButtons(); var card = new HeroCard { Buttons = buttons }; var attachment = new Attachment { Content = JObject.FromObject(card), }; message.Attachments = new List <Attachment> { attachment }; return(message); }
async Task IMessageQueue.QueueMessageAsync(IBotToUser botToUser, IMessageActivity message, CancellationToken token) { // This assumes that if InputHint is set on message, it is the right value that channel expects // and will NOT queue the message if (this.channelCapability.ShouldSetInputHint(message)) { // drain the queue while (this.queue.Count > 0) { var toUser = this.queue.Dequeue(); toUser.InputHint = InputHints.IgnoringInput; await botToUser.PostAsync(toUser, token); } queue.Enqueue(message); } else { await botToUser.PostAsync(message, token); } }
public static async Task RenderAsync(IBotToUser botToUser, IDialogStack stack, string message, CancellationToken token) { var frames = stack.Frames; var builder = new StringBuilder(); if (message != null) { builder.Append($"{message}").AppendLine().AppendLine(); } builder.Append($"Stack Frames ({frames.Count}): ").AppendLine().AppendLine(); builder.Append("~~~~").AppendLine().AppendLine(); for (int index = 0; index < frames.Count; ++index) { var frame = frames[index]; builder.Append($"* {index}: {ToString(frame)}").AppendLine().AppendLine(); } builder.Append("~~~~").AppendLine().AppendLine(); await botToUser.PostAsync(builder.ToString(), null, token); }
public static async Task PostWithTranslationAsync(this IBotToUser context, string message, string messageLocale, string userLocale) { if (messageLocale == null) { throw new ArgumentNullException(nameof(messageLocale)); } if (userLocale == null) { throw new ArgumentNullException(nameof(userLocale)); } try { var bingTranslatorClient = new BingTranslatorClient("Test187871", "dAnT3r/eIc8KedBRUgRCV+juxpf4Wl312jn1Bd2SXzk="); var translatedMessage = await bingTranslatorClient.Translate(message, messageLocale, userLocale); await context.PostAsync(translatedMessage, userLocale); } catch (Exception e) { await context.PostAsync("Translator service problems, please try again later", "en-US"); } }
/// <summary> /// Post a message and optional SSML to be sent to the user, using previous messages to establish a conversation context. /// </summary> /// <remarks> /// If the locale parameter is not set, locale of the incoming message will be used for reply. /// </remarks> /// <param name="botToUser">Communication channel to use.</param> /// <param name="text">The message text.</param> /// <param name="speak">The SSML markup for text to speech.</param> /// <param name="options">The options for the message.</param> /// <param name="locale">The locale of the text.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A task that represents the post operation.</returns> public static async Task SayAsync(this IBotToUser botToUser, string text, string speak = null, MessageOptions options = null, string locale = null, CancellationToken cancellationToken = default(CancellationToken)) { var message = botToUser.MakeMessage(); message.Text = text; message.Speak = speak; if (!string.IsNullOrEmpty(locale)) { message.Locale = locale; } if (options != null) { message.InputHint = options.InputHint; message.TextFormat = options.TextFormat; message.AttachmentLayout = options.AttachmentLayout; message.Attachments = options.Attachments; message.Entities = options.Entities; } await botToUser.PostAsync(message, cancellationToken); }
public AnimationCardScorable(IBotToUser botToUser, IBotData botData) : base(botToUser, botData) { }
public BotToUserTextWriter(IBotToUser inner, TextWriter writer) { SetField.NotNull(out this.inner, nameof(inner), inner); SetField.NotNull(out this.writer, nameof(writer), writer); }
public ManagerScorable(IBotToUser botToUser, List <string> managerList) { this.botToUser = botToUser; this.managerList = managerList; }
private static async void ShowCards(IBotToUser context) { var message = context.MakeMessage(); message.AttachmentLayout = AttachmentLayoutTypes.Carousel; var list = new List <Attachment>(); var card = new ThumbnailCard { Title = "Appointment Bookings", Subtitle = "Book an appointment or see your previous appointments", Images = new List <CardImage> { new CardImage($"{ConfigurationManager.AppSettings["BaseUrl"]}/img/BookingAppointments.png") }, Buttons = new List <CardAction> { new CardAction(ActionTypes.PostBack, "Appointment Bookings", null, MenuOptions.BookAppointment.ToString()) } }; list.Add(card.ToAttachment()); card = new ThumbnailCard { Title = "Hospitals Searching", Subtitle = "Find a hospital near you", Images = new List <CardImage> { new CardImage($"{ConfigurationManager.AppSettings["BaseUrl"]}/img/HospitalSearch.png") }, Buttons = new List <CardAction> { new CardAction(ActionTypes.PostBack, "Hospitals Searching", null, MenuOptions.SearchHospital.ToString()) } }; list.Add(card.ToAttachment()); card = new ThumbnailCard { Title = "Refund searching", Subtitle = "Check here your refund status", Images = new List <CardImage> { new CardImage($"{ConfigurationManager.AppSettings["BaseUrl"]}/img/Refund.png") }, Buttons = new List <CardAction> { new CardAction(ActionTypes.PostBack, "Pesquisa de reembolsos", null, MenuOptions.SearchRefund.ToString()) } }; list.Add(card.ToAttachment()); card = new ThumbnailCard { Title = "Balance Slip", Subtitle = "Request your balance slip here ", Images = new List <CardImage> { new CardImage($"{ConfigurationManager.AppSettings["BaseUrl"]}/img/Balance.jpg") }, Buttons = new List <CardAction> { new CardAction(ActionTypes.PostBack, "Balance Slip", null, MenuOptions.BalanceSlip.ToString()) } }; list.Add(card.ToAttachment()); card = new ThumbnailCard { Title = "Generate a barcode payment bill", Subtitle = "Request your bill here", Images = new List <CardImage> { new CardImage($"{ConfigurationManager.AppSettings["BaseUrl"]}/img/GenerateBarcodeSlip.png") }, Buttons = new List <CardAction> { new CardAction(ActionTypes.PostBack, "Generate a barcode payment bill", null, MenuOptions.BarcodeBillPayment.ToString()) } }; list.Add(card.ToAttachment()); message.Attachments = list; await context.PostAsync(message); }
public TranslatedBotToUser(IBotToUser inner, ITranslator translator) { SetField.NotNull(out this.inner, nameof(inner), inner); SetField.NotNull(out this.translator, nameof(translator), translator); }