public static async Task ForwardToReservationUser(string userId, IMessageActivity message, BotAdapter adapter, MicrosoftAppCredentials workingCredentials, ConversationReference contosoReference) { Tuple <ConversationReference, UserScubaData> foundReference; if (_recentReservations.TryGetValue(userId, out foundReference)) { _subscriberToUser.AddOrUpdate(userId, contosoReference, (key, oldValue) => contosoReference); Func <ITurnContext, Task> conversationCallback = GetConversationCallback(message, workingCredentials); await adapter.ContinueConversation(foundReference.Item1.Bot.Id, foundReference.Item1, conversationCallback); } }
public static async Task <bool> ForwardedToSubscriber(string userId, IMessageActivity message, BotAdapter adapter, MicrosoftAppCredentials workingCredentials) { ConversationReference foundReference = null; if (_subscriberToUser.TryGetValue(userId, out foundReference)) { Func <ITurnContext, Task> conversationCallback = GetConversationCallback(message, workingCredentials); await adapter.ContinueConversation(foundReference.Bot.Id, foundReference, conversationCallback); return(true); } return(false); }
private async void CompleteJob(BotAdapter adapter, string appId, ConversationReference conversation, int jobNumber) { await adapter.ContinueConversation(appId, conversation, async context => { // Get the job log from state, and retrieve the job. var jobLog = GetJobLog(context); var job = jobLog[jobNumber]; // Perform bookkeeping. job.Completed = true; // Send the user a proactive confirmation message. await context.SendActivity($"Job {job.JobNumber} is complete."); }); }
public static async Task NotifySubscribers(UserScubaData userScubaData, BotAdapter adapter, MicrosoftAppCredentials workingCredentials, ConversationReference reserverReference = null) { if (reserverReference != null) { var scubaReservation = new Tuple <ConversationReference, UserScubaData>(reserverReference, userScubaData); _recentReservations.AddOrUpdate(reserverReference.User.Id, scubaReservation, (key, oldValue) => scubaReservation); //todo: this should not be a hard coded url userScubaData.ChatWithUserUrl = "https://contososcubademo.azurewebsites.net?chatWithId=" + reserverReference.User.Id; //chatWithUserIdUrl = "Use this URL to chat with them: http://localhost:3979?chatWithId=" + reserverReference.User.Id; } string message = $"New scuba booking for {userScubaData.PersonalInfo.Name}"; var replaceInfo = new Dictionary <string, string>(); replaceInfo.Add("{{destination}}", userScubaData.Destination); replaceInfo.Add("{{school}}", userScubaData.School); replaceInfo.Add("{{longdate}}", Convert.ToDateTime(userScubaData.Date).ToString("dddd, MMMM dd")); replaceInfo.Add("{{number_of_people}}", userScubaData.NumberOfPeople); replaceInfo.Add("{{phone}}", userScubaData.PersonalInfo.Phone); replaceInfo.Add("{{email}}", userScubaData.PersonalInfo.Email); replaceInfo.Add("{{name}}", userScubaData.PersonalInfo.Name); replaceInfo.Add("{{protein_preference}}", userScubaData.MealOptions.ProteinPreference); replaceInfo.Add("{{vegan}}", userScubaData.MealOptions.Vegan ? "Yes" : "No"); replaceInfo.Add("{{allergy}}", userScubaData.MealOptions.Alergy); if (!string.IsNullOrEmpty(userScubaData.ChatWithUserUrl)) { replaceInfo.Add("{{url}}", userScubaData.ChatWithUserUrl); } var subscriberCardText = await CardProvider.GetCardText("SubscriberNotification", replaceInfo); var conversationCallback = GetConversationCallback(message, workingCredentials, subscriberCardText); await SendActionableMessage(userScubaData); foreach (var subscriber in _reservationSubscribers.Values) { await adapter.ContinueConversation(subscriber.Bot.Id, subscriber, conversationCallback); } }