public async Task <HttpResponseMessage> OAuthCallback([FromUri] string userId, [FromUri] string botId, [FromUri] string conversationId, [FromUri] string channelId, [FromUri] string serviceUrl, [FromUri] string code, CancellationToken token) { var conversationReference = new ConversationReference ( user: new ChannelAccount(id: SitecoreAuthenticationAPI.TokenDecoder(userId)), bot: new ChannelAccount(id: SitecoreAuthenticationAPI.TokenDecoder(botId)), conversation: new ConversationAccount(id: SitecoreAuthenticationAPI.TokenDecoder(conversationId)), channelId: SitecoreAuthenticationAPI.TokenDecoder(channelId), serviceUrl: SitecoreAuthenticationAPI.TokenDecoder(serviceUrl) ); // Exchange the Sitecore Auth code with Access token var accessToken = await SitecoreAuthenticationAPI.Instance().ExchangeCodeForAccessToken(conversationReference, code); // Create the message that is send to conversation to resume the login flow var msg = conversationReference.GetPostToUserMessage(); msg.Text = $"token:{accessToken.AccessToken}"; //// Resume the conversation to AuthenticationDialog await Conversation.ResumeAsync(conversationReference, msg); using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, msg)) { return(Request.CreateResponse("You are now logged in! Continue talking to the bot.")); } }
private async Task SendReminder(ConversationReference conversation, string replyText, CancellationToken token) { var connector = new ConnectorClient(new Uri(conversation.ServiceUrl), new MicrosoftAppCredentials()); var userAccount = new ChannelAccount(conversation.User.Id); var botAccount = new ChannelAccount(conversation.Bot.Id); Activity activity = conversation.GetPostToUserMessage(); // need to trust the service URL because otherwise the bot connector authentication will fail MicrosoftAppCredentials.TrustServiceUrl(conversation.ServiceUrl); // construct the reply to send back to the user IMessageActivity messageToSend = Activity.CreateMessageActivity(); messageToSend.ChannelId = conversation.ChannelId; messageToSend.From = botAccount; messageToSend.Recipient = userAccount; messageToSend.Conversation = new ConversationAccount(id: conversation.Conversation.Id); messageToSend.Text = replyText; messageToSend.Locale = "en-Us"; messageToSend.ServiceUrl = conversation.ServiceUrl; await connector.Conversations.SendToConversationAsync((Activity)messageToSend); }
static void SendToExistingConversation(ConversationReference convRef, IConversations conversations) { var existingConversationMessage = convRef.GetPostToUserMessage(); existingConversationMessage.Text = $"Hi, I've completed that long-running job and emailed it to you."; conversations.SendToConversation(existingConversationMessage); }
static void StartNewConversation(ConversationReference convRef, IConversations conversations) { ConversationResourceResponse convResponse = conversations.CreateDirectConversation(convRef.Bot, convRef.User); var notificationMessage = convRef.GetPostToUserMessage(); notificationMessage.Text = $"Hi, I haven't heard from you in a while. Want to play?"; notificationMessage.Conversation = new ConversationAccount(id: convResponse.Id); conversations.SendToConversation(notificationMessage); }
public async Task <HttpResponseMessage> Post([FromBody] ProactiveReply proactiveMessage) { var jsonData = File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/data.json")); ProactiveMessageData proactiveData = Newtonsoft.Json.JsonConvert.DeserializeObject <ProactiveMessageData>(jsonData); ConversationReference conversationRef = new ConversationReference { ActivityId = proactiveData.ActivityId, Bot = new ChannelAccount(proactiveData.FromId, proactiveData.FromName), ChannelId = proactiveData.ChannelId, Conversation = new ConversationAccount(id: proactiveData.ConversationId), User = new ChannelAccount(proactiveData.RecipientId, proactiveData.RecipientName), ServiceUrl = proactiveData.ServiceUrl }; var reply = conversationRef.GetPostToUserMessage().CreateReply(); reply.Text = $"Hey, I got solution for **{proactiveData.Message}**, {proactiveMessage.Text}"; var connector = new ConnectorClient(new Uri(proactiveData.ServiceUrl)); await connector.Conversations.ReplyToActivityAsync(reply); return(Request.CreateResponse(HttpStatusCode.OK)); }