// Send Activity to channels private async Task SendActivity(ITurnContext turnContext, string message) { Activity activity = turnContext.Activity.CreateReply(); // Fetching the gold rates GoldRate result = GoldRatesParser.GetRates().Result; // Messages based upon the entity's value if (string.IsNullOrEmpty(message)) { activity.Text = string.Format(Messages.GetRateMessages(), result.Carat24, result.Carat22); } else if (message == "22") { activity.Text = string.Format(Messages.GetRateCaratMessages(), message, result.Carat22); } else { activity.Text = string.Format(Messages.GetRateCaratMessages(), message, result.Carat24); } // Platform specific cards (Google) if (turnContext.Activity.ChannelId == "google") { var card = new GoogleBasicCard() { Content = new GoogleBasicCardContent() { Title = "Today's gold rate", Subtitle = "Keeping you up to date about the gold rates on daily basis.", FormattedText = activity.Text, Display = ImageDisplayOptions.DEFAULT, Image = new Image() { Url = "https://images-na.ssl-images-amazon.com/images/I/71lpB+tqfgL._SL210_QL95_BG0,0,0,0_FMpng_.png" }, }, }; turnContext.GoogleSetCard(card); } // Platform specific cards (Alexa) if (turnContext.Activity.ChannelId == "alexa") { turnContext.AlexaSetCard(new AlexaCard() { Type = AlexaCardType.Simple, Title = "Today's gold rate", Content = activity.Text }); } // Adaptive Cards can also be written here to support other OOTB channels await turnContext.SendActivityAsync(activity); }
/// <summary> /// Every conversation turn for our Echo Bot will call this method. /// There are no dialogs used, since it's "single turn" processing, meaning a single /// request and response. /// </summary> /// <param name="turnContext">A <see cref="ITurnContext"/> containing all the data needed /// for processing this conversation turn. </param> /// <param name="cancellationToken">(Optional) A <see cref="CancellationToken"/> that can be used by other objects /// or threads to receive notice of cancellation.</param> /// <returns>A <see cref="Task"/> that represents the work queued to execute.</returns> /// <seealso cref="BotStateSet"/> /// <seealso cref="ConversationState"/> /// <seealso cref="IMiddleware"/> public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { // Handle Message activity type, which is the main activity type for shown within a conversational interface // Message activities may contain text, speech, interactive cards, and binary or unknown attachments. // see https://aka.ms/about-bot-activity-message to learn more about the message and other activity types if (turnContext.Activity.Type == ActivityTypes.Message) { Activity activity = turnContext.Activity.CreateReply(); if (turnContext.Activity.ChannelId == "google") { // This could be saved in UserState object and retrieve as per the requirement. // For demo purposes, I am just using the hard-coded one. string userId = "<bank staff user id>"; var customer = await FlowHelper.GetFlowOutput(userId); string imageUrl = $"https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{customer.Address}/16?key=<bingmapskey>"; string processedImage = MapMaker.Process(imageUrl, "map"); // There's an issue which will be looked by the community. //Button button = new Button(); //button.Title = "Navigate"; //button.OpenUrlAction = new OpenUrlAction() { Url = "https://www.arafattehsin.com/" }; //Button[] buttons = { button }; var card = new GoogleBasicCard() { Content = new GoogleBasicCardContent() { Title = $"Home Delivery - {customer.Name}", Subtitle = customer.Address, FormattedText = "Kindly note that the customer requested for a call before arrival", Image = new Image() { Url = "https://d104b558.ngrok.io/images/map.jpg" }, // Buttons = { button }, Display = ImageDisplayOptions.DEFAULT }, }; activity.Text = $"You have to deliver a debit card for a new customer. You can reach him at {customer.MobileNumber}"; turnContext.GoogleSetCard(card); } await turnContext.SendActivityAsync(activity); } }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { var activity = turnContext.Activity.AsMessageActivity(); // For demo purposes, I am just using the hard-coded one. string userId = "userId of the staff"; var customer = await FlowHelper.GetFlowOutput(userId); string imageUrl = $"https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{customer.Address}/16?key=At-9uaLoghwXOeWXbc1bmz4XLcczj0hzL7YeBweBRr0Zx8BFIO9cl6XCU_Jj4sCw"; var url = MapMaker.Process(imageUrl, "map"); // There's an issue which will be looked by the community. Button button = new Button(); button.Title = "Navigate"; button.OpenUrlAction = new OpenUrlAction() { Url = $"https://www.google.com/maps/search/?api=1&query={customer.Address}" }; Button[] buttons = { button }; var card = new GoogleBasicCard() { Content = new GoogleBasicCardContent() { Title = $"Home Delivery - {customer.Name}", Subtitle = customer.Address, FormattedText = "Kindly note that the customer requested for a call before arrival", Image = new Image() { // Compression issue of an image, have to look into it later on. Url = $"http://6826849a.ngrok.io/images/map.jpeg" }, Buttons = buttons, Display = ImageDisplayOptions.DEFAULT }, }; activity.Text = $"You have to deliver a debit card for a new customer. You can reach him at {customer.MobileNumber}"; turnContext.GoogleSetCard(card); await turnContext.SendActivityAsync(activity); }