//This will send an adhoc message to the user
        public static async Task Cancel(string conversationId, string channelId)
        {
            var userAccount = new ChannelAccount(toId, toName);
            var botAccount  = new ChannelAccount(fromId, fromName);
            var connector   = new ConnectorClient(new Uri(serviceUrl));

            IMessageActivity message = Activity.CreateMessageActivity();

            if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(channelId))
            {
                message.ChannelId = channelId;
            }
            else
            {
                conversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;
            }
            message.From         = botAccount;
            message.Recipient    = userAccount;
            message.Conversation = new ConversationAccount(id: conversationId);
            message.Locale       = "en-Us";
            message.Text         = "Reservation Cancellation Notification";
            await RideReservation.GenerateHeroCardNotificationMessage(message, reservation, "Cancellation Receipt", "Your reservation has been cancelled");

            reservation = null;
            await connector.Conversations.SendToConversationAsync((Activity)message);
        }
        //This will send an adhoc message to the user
        public static async Task Resume(string conversationId, string channelId)
        {
            var userAccount = new ChannelAccount(toId, toName);
            var botAccount  = new ChannelAccount(fromId, fromName);
            var connector   = new ConnectorClient(new Uri(serviceUrl));

            IMessageActivity message = Activity.CreateMessageActivity();

            if (!string.IsNullOrEmpty(conversationId) && !string.IsNullOrEmpty(channelId))
            {
                message.ChannelId = channelId;
            }
            else
            {
                conversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id;
            }
            message.From         = botAccount;
            message.Recipient    = userAccount;
            message.Conversation = new ConversationAccount(id: conversationId);
            message.Locale       = "en-Us";
            message.Text         = "Driver Arrived Notification";
            await RideReservation.GenerateAdaptiveCardNotificationMessage(message, reservation);

            await connector.Conversations.SendToConversationAsync((Activity)message);
        }
コード例 #3
0
 private void SaveReservation(IMessageActivity message, RideReservation reservation)
 {
     //We need to keep this data so we know who to send the message to. Assume this would be stored somewhere, e.g. an Azure Table
     ConversationStarter.toId           = message.From.Id;
     ConversationStarter.toName         = message.From.Name;
     ConversationStarter.fromId         = message.Recipient.Id;
     ConversationStarter.fromName       = message.Recipient.Name;
     ConversationStarter.serviceUrl     = message.ServiceUrl;
     ConversationStarter.channelId      = message.ChannelId;
     ConversationStarter.conversationId = message.Conversation.Id;
     ConversationStarter.reservation    = reservation;
 }
        private static Task GenerateHeroCardConfirmMessage(IMessageActivity confirmation, RideReservation state)
        {
            Regex geoCoordinateRegex = new Regex(@"(-?\d+.?\d+),(-?\d+.?\d+)", RegexOptions.IgnoreCase);

            var messageText = "Ready to submit your reservation?";
            var cardText    = confirmation.Text.Replace(messageText, "").Trim();

            confirmation.Text = messageText;

            // check if pickup location is lat,lon
            if (geoCoordinateRegex.IsMatch(state.PickUpLocation))
            {
                // replace coordinates with verbiage
                cardText = cardText.Replace(state.PickUpLocation, "Your current location");
            }

            List <CardImage> cardImages = new List <CardImage>();

            cardImages.Add(new CardImage(url: $"https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/Routes?mapSize=400,200&wp.0={state.PickUpLocation};64;1&wp.1={state.DropLocation};66;2&key=An5x3zGAXYxr6cTaSvbsWilLxUBA75GoOXM3KndDNtQMn2ZAKRGjgnZw2XLMJYtl"));

            HeroCard confirmCard = new HeroCard()
            {
                Title    = $"Trip Details",
                Subtitle = $"",
                Images   = cardImages,
                Text     = cardText
            };

            Attachment confirmAttachment = confirmCard.ToAttachment();

            confirmation.Attachments.Add(confirmAttachment);
            return(Task.CompletedTask);
        }
        private static async Task <FormPrompt> MyPrompter(IDialogContext context, FormPrompt prompt, RideReservation state, IField <RideReservation> field)
        {
            var preamble      = context.MakeMessage();
            var promptMessage = context.MakeMessage();

            if (prompt.GenerateMessages(preamble, promptMessage))
            {
                await context.PostAsync(preamble);
            }
            if (field.Name.ToLower().StartsWith("confirmation"))
            {
                await GenerateHeroCardConfirmMessage(promptMessage, state);
            }
            await context.PostAsync(promptMessage);

            return(prompt);
        }
        public static Task GenerateAdaptiveCardNotificationMessage(IMessageActivity message, RideReservation state)
        {
            try
            {
                var tripImageUrl = $"https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/Routes?mapSize=400,200&wp.0={state.PickUpLocation};64;1&wp.1={state.DropLocation};66;2&key=An5x3zGAXYxr6cTaSvbsWilLxUBA75GoOXM3KndDNtQMn2ZAKRGjgnZw2XLMJYtl";

                // read the json in from our file
                WebClient    client = new WebClient();
                Stream       stream = client.OpenRead("https://vpbotlabssa.blob.core.windows.net/adaptive-cards/NotificationCard.json");
                StreamReader reader = new StreamReader(stream);
                string       json   = reader.ReadToEnd();
                // replace the trip url
                json = json.Replace("<TRIPURL>", tripImageUrl);
                // use Newtonsofts JsonConvert to deserialized the json into a C# AdaptiveCard object
                AdaptiveCard card = JsonConvert.DeserializeObject <AdaptiveCard>(json);
                // put the adaptive card as an attachment to the reply message
                message.Attachments.Add(new Attachment
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content     = card
                });
            }
            catch (Exception e)
            {
                // if an error occured add the error text as the message
                message.Text = e.Message;
            }
            return(Task.CompletedTask);
        }
        public static Task GenerateHeroCardNotificationMessage(IMessageActivity message, RideReservation state, string subTitle, string text)
        {
            List <CardImage> cardImages = new List <CardImage>();

            cardImages.Add(new CardImage(url: $"https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/Routes?mapSize=400,200&wp.0={state.PickUpLocation};64;1&wp.1={state.DropLocation};66;2&key=An5x3zGAXYxr6cTaSvbsWilLxUBA75GoOXM3KndDNtQMn2ZAKRGjgnZw2XLMJYtl"));

            HeroCard notificationCard = new HeroCard()
            {
                Title    = $"Taxi Bot Notification",
                Subtitle = subTitle,
                Images   = cardImages,
                Text     = text
            };

            Attachment notificationAttachment = notificationCard.ToAttachment();

            message.Attachments.Add(notificationAttachment);
            return(Task.CompletedTask);
        }