Ejemplo n.º 1
0
        /// <summary>
        /// Gets the established conversation.
        /// </summary>
        /// <param name="conversationId">The conversation identifier.</param>
        /// <returns></returns>
        public ApiResponse <EstablishedConversationModel> Send(IHubsterAuthorizer authorizer, Guid conversationId)
        {
            var apiResponse = new ApiResponse <EstablishedConversationModel>();

            if (authorizer.EnsureLifespan(apiResponse) == false)
            {
                return(apiResponse);
            }

            var client      = new RestClient(_hostUrl);
            var restRequest = new RestRequest($"/api/v1/conversations/{conversationId}/established", Method.GET)
            {
                Timeout = 20000
            };

            restRequest.AddHeader("Content-Type", "application/json");
            restRequest.AddHeader("Authorization", $"{authorizer.Token.TokenType} {authorizer.Token.AccessToken}");
            restRequest.AddHeader("Origin", _origin);

            var restResponse = client.Execute(restRequest);

            apiResponse = ExtractResponse <EstablishedConversationModel>(restResponse);

            return(apiResponse);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Establishes the conversation.
        /// </summary>
        /// <param name="authorizer">The authorizer.</param>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public ApiResponse <EstablishedConversationModel> Get(IHubsterAuthorizer authorizer, EstablishConversationRequestModel request)
        {
            var apiResponse = new ApiResponse <EstablishedConversationModel>();

            if (authorizer.EnsureLifespan(apiResponse) == false)
            {
                return(apiResponse);
            }

            var client      = new RestClient(_hostUrl);
            var restRequest = new RestRequest("/api/v1/conversations/establish", 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(request);

            restRequest.AddParameter("application/json", body, ParameterType.RequestBody);

            var restResponse = client.Execute(restRequest);

            apiResponse = ExtractResponse <EstablishedConversationModel>(restResponse);

            return(apiResponse);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Establishes the conversation.
        /// </summary>
        /// <param name="authorizer">The authorizer.</param>
        /// <param name="conversationId">The conversation identifier.</param>
        /// <param name="lastEventId">The last event identifier.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public ApiResponse <IEnumerable <DirectActivityModel> > Get(IHubsterAuthorizer authorizer, Guid conversationId, long lastEventId, IntegrationType type)
        {
            var apiResponse = new ApiResponse <IEnumerable <DirectActivityModel> >();

            if (authorizer.EnsureLifespan(apiResponse) == false)
            {
                return(apiResponse);
            }

            var client      = new RestClient(_hostUrl);
            var restRequest = new RestRequest($"/api/v1/interactions/activities/{conversationId}", Method.GET)
            {
                Timeout = 20000
            };

            restRequest.AddHeader("Content-Type", "application/json");
            restRequest.AddHeader("Authorization", $"{authorizer.Token.TokenType} {authorizer.Token.AccessToken}");
            restRequest.AddHeader("Origin", _origin);

            restRequest.AddParameter("leid", lastEventId);
            restRequest.AddParameter("type", type.ToString());

            var restResponse = client.Execute(restRequest);

            apiResponse = ExtractResponse <IEnumerable <DirectActivityModel> >(restResponse);

            return(apiResponse);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the specified authorizer.
        /// </summary>
        /// <param name="authorizer">The authorizer.</param>
        /// <param name="conversationId">The conversation identifier.</param>
        /// <param name="lastEventId">The last event identifier.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public ApiResponse <IEnumerable <DirectActivityModel> > Get(IHubsterAuthorizer authorizer, Guid conversationId, long lastEventId, IntegrationType type)
        {
            var apiResponse = _engineAccess.Get(authorizer, conversationId, lastEventId, type);

            return(apiResponse);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Establishes the conversation.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public ApiResponse <EstablishedConversationModel> Establish(IHubsterAuthorizer authorizer, EstablishConversationRequestModel request)
        {
            var apiResponse = _engineAccess.Establish(authorizer, request);

            return(apiResponse);
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the specified authorizer.
        /// </summary>
        /// <param name="authorizer">The authorizer.</param>
        /// <param name="conversation">The conversation.</param>
        /// <param name="lastEventId">The last event identifier.</param>
        /// <returns></returns>
        public ApiResponse <IEnumerable <DirectActivityModel> > Get(IHubsterAuthorizer authorizer, EstablishedConversationModel conversation, long lastEventId)
        {
            var apiResponse = _engineAccess.Get(authorizer, conversation.ConversationId.Value, lastEventId, IntegrationType.Customer);

            return(apiResponse);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets all established by hub identifier.
        /// </summary>
        /// <param name="authorizer">The authorizer.</param>
        /// <param name="hubId">The hub identifier.</param>
        /// <returns></returns>
        public ApiResponse <IEnumerable <EstablishedConversationModel> > GetAllEstablishedByHubId(IHubsterAuthorizer authorizer, Guid hubId)
        {
            var apiResponse = _engineAccess.GetAllEstablishedByHubId(authorizer, hubId);

            return(apiResponse);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the established conversation.
        /// </summary>
        /// <param name="conversationId">The conversation identifier.</param>
        /// <returns></returns>
        public ApiResponse <EstablishedConversationModel> GetEstablished(IHubsterAuthorizer authorizer, Guid conversationId)
        {
            var apiResponse = _engineAccess.GetEstablished(authorizer, conversationId);

            return(apiResponse);
        }