public override async Task <ResourceResponse[]> SendActivities(ITurnContext context, Activity[] activities) { AssertBotFrameworkContext(context); List <ResourceResponse> responses = new List <ResourceResponse>(); BotFrameworkTurnContext bfContext = context as BotFrameworkTurnContext; MicrosoftAppCredentials appCredentials = await GetAppCredentials(bfContext.BotAppId); foreach (var activity in activities) { ResourceResponse response; if (activity.Type == ActivityTypesEx.Delay) { // The Activity Schema doesn't have a delay type build in, so it's simulated // here in the Bot. This matches the behavior in the Node connector. int delayMs = (int)activity.Value; await Task.Delay(delayMs).ConfigureAwait(false); // In the case of a Delay, just create a fake one. Match the incoming activityId if it's there. response = new ResourceResponse(activity.Id ?? string.Empty); } else { var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl), appCredentials); response = await connectorClient.Conversations.SendToConversationAsync(activity).ConfigureAwait(false); } // Collect all the responses that come from the service. responses.Add(response); } return(responses.ToArray()); }
public override async Task DeleteActivity(ITurnContext context, ConversationReference reference) { AssertBotFrameworkContext(context); BotFrameworkTurnContext bfContext = context as BotFrameworkTurnContext; MicrosoftAppCredentials appCredentials = await GetAppCredentials(bfContext.BotAppId); var connectorClient = new ConnectorClient(new Uri(context.Activity.ServiceUrl), appCredentials); await connectorClient.Conversations.DeleteActivityAsync(reference.Conversation.Id, reference.ActivityId); }
public async Task ProcessActivity(string authHeader, Activity activity, Func <ITurnContext, Task> callback) { BotAssert.ActivityNotNull(activity); ClaimsIdentity claimsIdentity = await JwtTokenValidation.AuthenticateRequest(activity, authHeader, _credentialProvider, _httpClient); // For requests from channel App Id is in Audience claim of JWT token. For emulator it is in AppId claim. For // unauthenticated requests we have anonymouse identity provided auth is disabled. string botAppId = GetBotId(claimsIdentity); var context = new BotFrameworkTurnContext(botAppId, this, activity); await base.RunPipeline(context, callback).ConfigureAwait(false); }
public static void AssertBotFrameworkContext(ITurnContext context) { BotAssert.ContextNotNull(context); BotFrameworkTurnContext bfContext = context as BotFrameworkTurnContext; if (bfContext == null) { throw new InvalidOperationException($"BotFramework Context is required. Incorrect context type: {context.GetType().Name}"); } }
public override async Task <ResourceResponse> UpdateActivity(ITurnContext context, Activity activity) { AssertBotFrameworkContext(context); BotFrameworkTurnContext bfContext = context as BotFrameworkTurnContext; MicrosoftAppCredentials appCredentials = await GetAppCredentials(bfContext.BotAppId); var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl), appCredentials); return(await connectorClient.Conversations.UpdateActivityAsync(activity)); }
public Task ContinueConversation(string botAppId, ConversationReference reference, Func <ITurnContext, Task> callback) { if (string.IsNullOrWhiteSpace(botAppId)) { throw new ArgumentNullException(nameof(botAppId)); } if (reference == null) { throw new ArgumentNullException(nameof(reference)); } if (callback == null) { throw new ArgumentNullException(nameof(callback)); } var context = new BotFrameworkTurnContext(botAppId, this, reference.GetPostToBotMessage()); return(RunPipeline(context, callback)); }