private static void Display(DirectActivityModel activity) { var color = ConsoleColor.Yellow; switch (activity.Sender.IntegrationType) { case IntegrationType.Agent: color = ConsoleColor.Cyan; break; case IntegrationType.Hubster: color = ConsoleColor.Green; break; case IntegrationType.Bot: color = ConsoleColor.White; break; } var activityMessage = JsonConvert.SerializeObject(activity, Formatting.Indented); Display(activityMessage, color); }
/// <summary> /// Sends the specified authorizer. /// </summary> /// <param name="authorizer">The authorizer.</param> /// <param name="conversationId">The conversation identifier.</param> /// <param name="activity">The activity model.</param> /// <returns></returns> public ApiResponse <DirectResponseModel> Send(IHubsterAuthorizer authorizer, Guid conversationId, DirectActivityModel activity) { var apiResponse = _engineAccess.Send(authorizer, conversationId, activity, "business"); return(apiResponse); }
/// <summary> /// Sends the specified authorizer. /// </summary> /// <param name="authorizer">The authorizer.</param> /// <param name="conversation">The conversation.</param> /// <param name="activity">The activity.</param> /// <returns></returns> public ApiResponse <DirectResponseModel> Send(IHubsterAuthorizer authorizer, EstablishedConversationModel conversation, DirectActivityModel activity) { var apiResponse = _engineAccess.Send(authorizer, conversation.ConversationId.Value, activity, "customer"); return(apiResponse); }
/// <summary> /// Sends the specified authorizer. /// </summary> /// <param name="authorizer">The authorizer.</param> /// <param name="conversationId">The conversation identifier.</param> /// <param name="activity">The activity.</param> /// <param name="path">The path.</param> /// <returns></returns> public ApiResponse <DirectResponseModel> Send(IHubsterAuthorizer authorizer, Guid conversationId, DirectActivityModel activity, string path) { var apiResponse = new ApiResponse <DirectResponseModel>(); if (authorizer.EnsureLifespan(apiResponse) == false) { return(apiResponse); } var url = $"/inbound/{path}/v1/direct/activity/{conversationId}"; if (authorizer.Token.TokenType == "WebBearer") { url = $"/inbound/customer/v1/web-chat/{conversationId}"; } var client = new RestClient(_hostUrl); var restRequest = new RestRequest(url, Method.POST) { Timeout = 20000 }; restRequest.AddHeader("Content-Type", "application/json"); restRequest.AddHeader("Authorization", $"{authorizer.Token.TokenType} {authorizer.Token.AccessToken}"); restRequest.AddHeader("Origin", _origin); var body = JsonConvert.SerializeObject(activity); restRequest.AddParameter("application/json", body, ParameterType.RequestBody); var restResponse = client.Execute(restRequest); apiResponse = ExtractResponse <DirectResponseModel>(restResponse); return(apiResponse); }