public static async Task SendMessageAsync( ConversationChannelData userCommunicationChannelInfo, SupportedLanguage userPreferedLangue, Models.Message messageToSend, Models.MessageOption messgeOptions = null) { var userAccount = new ChannelAccount(userCommunicationChannelInfo.UserId, userCommunicationChannelInfo.UserName); var botAccount = new ChannelAccount(userCommunicationChannelInfo.BotId, userCommunicationChannelInfo.BotName); var connector = new ConnectorClient(new Uri(userCommunicationChannelInfo.ServiceUrl)); // Create a new message. IMessageActivity proactiveMessageActivity = Activity.CreateMessageActivity(); if (!string.IsNullOrEmpty(userCommunicationChannelInfo.ConversationId) && !string.IsNullOrEmpty(userCommunicationChannelInfo.ChannelId)) { // If conversation ID and channel ID was stored previously, use it. proactiveMessageActivity.ChannelId = userCommunicationChannelInfo.ChannelId; } else { // Conversation ID was not stored previously, so create a conversation. // Note: If the user has an existing conversation in a channel, this will likely create a new conversation window. userCommunicationChannelInfo.ConversationId = (await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount)).Id; } // Set the address-related properties in the message and send the message. proactiveMessageActivity.From = botAccount; proactiveMessageActivity.Recipient = userAccount; proactiveMessageActivity.Conversation = new ConversationAccount(id: userCommunicationChannelInfo.ConversationId); InitializeMessage(proactiveMessageActivity, userPreferedLangue, messageToSend, messgeOptions); await connector.Conversations.SendToConversationAsync((Activity)proactiveMessageActivity); }
private async Task <string> PostMaintenanceServiceRequestForTheUser() { var userFilledFormValues = this.ConversationData.ServiceBookingForm; var userRequestedDelivaryDate = new System.DateTime( userFilledFormValues.Year.Value, userFilledFormValues.Month.Value, userFilledFormValues.Day.Value, userFilledFormValues.DayOrNight == "PM" ? userFilledFormValues.Hour.Value + 12 : userFilledFormValues.Hour.Value, userFilledFormValues.Minutes.Value, 0); var conversationChannelData = new ConversationChannelData( this.UserProfile.Id, this.UserProfile.Name, this.ConversationData.BotId, this.ConversationData.BotName, this.UserProfile.ChannelId, this.ConversationData.ConversationId, this.ConversationData.ServiceUrl); var serviceBookingRequest = new BookingRequest( userFilledFormValues.RequestedService.Value, userFilledFormValues.RequiredServiceDescription, userFilledFormValues.DeliveryLocation, userRequestedDelivaryDate, conversationChannelData, this.UserProfile.PreferredLanguage.Value); var stringContent = new StringContent(JsonConvert.SerializeObject(serviceBookingRequest), Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("http://localhost:2614/api/MaintenanceServicesRequests/AddRequest/", stringContent); return(await response.Content.ReadAsAsync <string>()); }