/// <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));
        }
Example #2
0
        public async Task RenderAsync(List <ISesamError> errors)
        {
            var message = botToUser.MakeMessage();

            message = BuildMessageFromErrors(errors, message);
            await botToUser.PostAsync(message);
        }
        private static async Task SendMessageAsync(IBotToUser context, string text)
        {
            var message = context.MakeMessage();

            message.Text = text;
            await context.PostAsync(message);
        }
        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();
            }
        }
Example #5
0
        async Task IPostToBot.PostAsync(IActivity activity, CancellationToken token)
        {
            try
            {
                await _inner.PostAsync(activity, token);
            }
            catch (Exception error)
            {
                try
                {
                    if (Debugger.IsAttached)
                    {
                        var message = _botToUser.MakeMessage();
                        message.Text        = $"Exception: { error.Message}";
                        message.Attachments = new[]
                        {
                            new Attachment(MediaTypeNames.Text.Plain, content: error.StackTrace)
                        };

                        await _botToUser.PostAsync(message, token);
                    }
                    else
                    {
                        await _botToUser.PostAsync("Ops! I'm still handle the previous message...", cancellationToken : token);
                    }
                }
                catch (Exception e)
                {
                    _trace.WriteLine(e);
                }

                throw;
            }
        }
        private static async Task SendMessageAsync(IBotToUser context, Attachment attachment)
        {
            var message = context.MakeMessage();

            message.Attachments.Add(attachment);
            await context.PostAsync(message);
        }
Example #7
0
        /// <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, 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);
        }
Example #9
0
        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);
        }
Example #10
0
        /// <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);
        }
Example #11
0
        async Task IPostToBot.PostAsync(IActivity activity, CancellationToken token)
        {
            try
            {
                await _inner.PostAsync(activity, token);
            }
            catch (Exception error)
            {
                var logger = LogManager.GetCurrentClassLogger();
                logger.LogError("Unhandled exception during dialog.", error.Message, error.ToString(), activity.Conversation.Id);

                try
                {
                    if (Debugger.IsAttached)
                    {
                        var message = _botToUser.MakeMessage();
                        message.Text        = $"Exception: { error }";
                        message.Attachments = new[]
                        {
                            new Attachment(MediaTypeNames.Text.Plain, content: error.StackTrace)
                        };

                        await _botToUser.PostAsync(message, token);
                    }
                    else
                    {
                        var message = _botToUser.MakeMessage();
                        message.Text = "Chatboten har støtt på et uventet problem. Vennligst prøv igjen senere eller ring oss";
                        await _botToUser.PostAsync(message, token);
                    }
                }
                catch (Exception inner)
                {
                    _trace.WriteLine(inner);
                    logger.LogError("Unhandled exception during handling an error.", inner.Message, inner.ToString(), activity.Conversation.Id);
                }

                throw;
            }
        }
        protected override async Task PostAsync(IActivity item, string state, CancellationToken token)
        {
            var message = item as IMessageActivity;

            if (message != null)
            {
                var reply = _botToUser.MakeMessage();

                reply.Text = answers.SelectRandomdly();

                await _botToUser.PostAsync(reply);
            }
        }
        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);
        }
        /// <summary>
        /// Replay activity to IBotToUser.
        /// </summary>
        /// <param name="activity">Activity.</param>
        /// <returns>Task.</returns>
        public async Task Replay(IActivity activity)
        {
            if (activity is IMessageActivity)
            {
                var msg = _botToUser.MakeMessage();
                msg.Text = _header(activity);
                await _botToUser.PostAsync(msg);

                var act = JsonConvert.DeserializeObject <Activity>(JsonConvert.SerializeObject(activity));
                if (act.ChannelId != msg.ChannelId)
                {
                    act.ChannelData = null;
                }
                act.From         = msg.From;
                act.Recipient    = msg.Recipient;
                act.ReplyToId    = msg.ReplyToId;
                act.ChannelId    = msg.ChannelId;
                act.Conversation = msg.Conversation;
                await _botToUser.PostAsync(act);
            }
        }
Example #15
0
        /// <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);
        }
Example #16
0
        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);
        }
Example #17
0
 IMessageActivity IBotToUser.MakeMessage()
 {
     return(inner.MakeMessage());
 }
 public IMessageActivity MakeMessage()
 {
     return(inner.MakeMessage());
 }