private async Task HandleJoinCompetitionAction(InvokeActionData invokeActionData, Activity activity) { var competition = await _competitionService.AddCompetitor(invokeActionData.CompetitionId, activity.From.AadObjectId, activity.From.Name); var updatedActivity = _activityBuilder.CreateMainActivity(competition); using (var botClient = _botClientFactory.CreateBotClient(activity.ServiceUrl)) { await botClient.UpdateActivityAsync(competition.ChannelId, competition.MainActivityId, updatedActivity); } }
public static async Task <HttpResponseMessage> SendTeamsInvoke( this HttpClient httpClient, InvokeActionData invokeValue, ChannelAccount from = null) { var activity = new Activity { ServiceUrl = "https://service-url.com", ChannelId = "msteams", Type = "invoke", Value = invokeValue, From = from ?? new ChannelAccount("id", "name") }; return(await httpClient.SendActivity(activity)); }
public static async Task <HttpResponseMessage> SendTeamsTaskFetch( this HttpClient httpClient, InvokeActionData invokeValue, ChannelAccount from = null) { invokeValue.Type = InvokeActionData.TypeTaskFetch; var activity = new Activity { Name = "task/fetch", ServiceUrl = "https://service-url.com", ChannelId = "msteams", Type = ActivityTypes.Invoke, Value = new { data = invokeValue }, From = from ?? new ChannelAccount("id", "name") }; return(await httpClient.SendActivity(activity)); }
private async Task <TaskModuleTaskInfoResponse> HandleViewCompetitionDetailAction(InvokeActionData invokeActionData, Activity activity) { var competition = await _competitionService.GetCompetition(invokeActionData.CompetitionId); var taskInfoResponse = _activityBuilder.CreateCompetitionDetailTaskInfoResponse(competition); return(taskInfoResponse); }
public async Task <IActionResult> GetMessage() { // Get the incoming activity Activity activity; using (var streamReader = new StreamReader(Request.Body)) { var bodyString = await streamReader.ReadToEndAsync(); activity = JsonConvert.DeserializeObject <Activity>(bodyString); } _logger.LogInformation($"ChannelId:{activity.ChannelId} Type:{activity.Type} Action:{activity.Action} ValueType:{activity.ValueType} Value:{activity.Value}"); _logger.LogInformation("Input activity: {activity}", JsonConvert.SerializeObject(activity)); // Authenticate the request var(isAuthenticated, authenticationErrorMessage) = await _botValidator.Validate(Request); if (!isAuthenticated) { return(Unauthorized(authenticationErrorMessage)); } _logger.LogInformation($"Authentication check succeeded."); // Validate the channel of the incoming activity if (activity.ChannelId != "msteams") { await _handlers.NonTeamsChannel.Handle(activity); return(Ok()); } // Handle the activity if (activity.Type == ActivityTypes.Invoke) { if (activity.Name == "composeExtension/fetchTask" && activity.GetCommandId() == "create") { var response = await _handlers.ComposeStartForm.Handle(activity); return(OkWithNewtonsoftJson(response)); } else if (activity.Name == "composeExtension/submitAction" && activity.GetCommandId() == "create") { if (activity.GetBotMessagePreviewAction() == "edit") { var response = await _handlers.ComposeEditAgain.Handle(activity); return(OkWithNewtonsoftJson(response)); } if (activity.GetBotMessagePreviewAction() == "send") { await _handlers.ComposeSend.Handle(activity, this.Url); return(Ok()); } else { ComposeActionData composeActionData = activity.GetComposeActionData(); var response = await _handlers.ComposePreview.Handle(activity); return(OkWithNewtonsoftJson(response)); } } else { InvokeActionData invokeActionData = activity.GetInvokeActionData(); switch (invokeActionData.UserAction) { case InvokeActionType.Join: await _handlers.ActionJoinCompetition.Handle(activity); return(Ok()); case InvokeActionType.ViewDetail: var competitionDetailResponse = await _handlers.ActionViewCompetitionDetail.Handle(activity); return(OkWithNewtonsoftJson(competitionDetailResponse)); case InvokeActionType.EditDraft: var editDraftCompetitionResponse = await _handlers.ActionEditDraftCompetition.Handle(activity); return(OkWithNewtonsoftJson(editDraftCompetitionResponse)); case InvokeActionType.SaveDraft: await _handlers.ActionSaveDraftCompetition.Handle(activity); return(Ok()); case InvokeActionType.ActivateCompetition: await _handlers.ActionSaveDraftCompetition.Handle(activity); var activateCompetitionResponse = await _handlers.ActionActivateCompetition.Handle(activity, this.Url); return(OkWithNewtonsoftJson(activateCompetitionResponse)); default: throw new Exception("Unknown invoke action type: " + invokeActionData.UserAction); } } } else if (activity.Type == ActivityTypes.Message) { var text = activity.GetTrimmedText(); if (text.Equals("help", StringComparison.InvariantCultureIgnoreCase)) { await _handlers.CommandHelp.Handle(activity); } else if (text.Equals("start", StringComparison.InvariantCultureIgnoreCase)) { await _handlers.CommandCreateDraftCompetition.Handle(activity); } else { if (_handlers.CommandCreateCompetition.CanHandle(activity)) { await _handlers.CommandCreateCompetition.Handle(activity, this.Url); } else { await _handlers.UnknownCommand.Handle(activity); } } return(Ok()); } else if (activity.Type == ActivityTypes.ConversationUpdate) { var botSelf = activity.Recipient.Id; if ((activity.MembersAdded != null) && (activity.MembersAdded.Count > 0) && (activity.MembersAdded[0].Id == botSelf)) { await _handlers.AddedToNewChannel.Handle(activity); return(Ok()); } } return(Ok()); }