From 37c683f083fccbc1618b29522f99c80d4b567ae9 Mon Sep 17 00:00:00 2001 From: Prashant Srivastav Date: Mon, 15 Jun 2026 21:07:14 +0800 Subject: [PATCH] chore: add assistant deployment REST APIs --- .../create_assistant_api_deployment_rest.go | 295 +++++ ...assistant_debugger_deployment_rest_test.go | 502 ++++++-- .../create_assistant_phone_deployment_rest.go | 338 +++++ ...te_assistant_phone_deployment_rest_test.go | 169 +++ ...ate_assistant_webplugin_deployment_rest.go | 302 +++++ ...eate_assistant_whatsapp_deployment_rest.go | 200 +++ .../create_other_deployments_rest_test.go | 210 ++++ .../get_all_assistant_api_deployment_rest.go | 223 ++++ ..._all_assistant_debugger_deployment_rest.go | 223 ++++ ...get_all_assistant_phone_deployment_rest.go | 236 ++++ ...all_assistant_webplugin_deployment_rest.go | 225 ++++ ..._all_assistant_whatsapp_deployment_rest.go | 188 +++ .../get_assistant_api_deployment_rest.go | 151 +++ .../get_assistant_debugger_deployment_rest.go | 151 +++ .../get_assistant_deployment_rest_test.go | 265 ++++ .../get_assistant_phone_deployment_rest.go | 165 +++ ...get_assistant_webplugin_deployment_rest.go | 153 +++ .../get_assistant_whatsapp_deployment_rest.go | 117 ++ api/assistant-api/router/assistant.go | 14 + openapi/artifacts/assistant-api.yaml | 1120 ++++++++++++++++- openapi/artifacts/common.yaml | 137 ++ openapi/assistant.gen.go | 279 ++++ openapi/common.gen.go | 129 ++ pkg/errors/create_assistant_deployment.go | 588 +++++++++ 24 files changed, 6302 insertions(+), 78 deletions(-) create mode 100644 api/assistant-api/api/assistant-deployment/create_assistant_api_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/create_assistant_phone_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/create_assistant_phone_deployment_rest_test.go create mode 100644 api/assistant-api/api/assistant-deployment/create_assistant_webplugin_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/create_assistant_whatsapp_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/create_other_deployments_rest_test.go create mode 100644 api/assistant-api/api/assistant-deployment/get_all_assistant_api_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_all_assistant_debugger_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_all_assistant_phone_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_all_assistant_webplugin_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_all_assistant_whatsapp_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_assistant_api_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_assistant_debugger_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_assistant_deployment_rest_test.go create mode 100644 api/assistant-api/api/assistant-deployment/get_assistant_phone_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_assistant_webplugin_deployment_rest.go create mode 100644 api/assistant-api/api/assistant-deployment/get_assistant_whatsapp_deployment_rest.go diff --git a/api/assistant-api/api/assistant-deployment/create_assistant_api_deployment_rest.go b/api/assistant-api/api/assistant-deployment/create_assistant_api_deployment_rest.go new file mode 100644 index 00000000..8767fac7 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/create_assistant_api_deployment_rest.go @@ -0,0 +1,295 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) CreateAssistantApiDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.CreateAssistantApiDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.CreateAssistantApiDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + var request openapi.CreateAssistantApiDeploymentRequest + if err := c.ShouldBindJSON(&request); err != nil { + deploymentApi.logger.Errorf("create assistant api deployment invalid request: %v", err) + c.JSON(pkg_errors.CreateAssistantApiDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(string(request.AssistantId), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.CreateAssistantApiDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.IdealTimeout) && !validator.Between(int(*request.IdealTimeout), 15, 120) { + c.JSON(pkg_errors.CreateAssistantApiDeploymentInvalidIdealTimeout.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidIdealTimeout.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentInvalidIdealTimeout.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidIdealTimeout.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidIdealTimeout.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.IdealTimeoutBackoff) && !validator.Between(int(*request.IdealTimeoutBackoff), 0, 5) { + c.JSON(pkg_errors.CreateAssistantApiDeploymentInvalidTimeoutBackoff.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidTimeoutBackoff.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentInvalidTimeoutBackoff.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidTimeoutBackoff.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidTimeoutBackoff.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.MaxSessionDuration) && !validator.Between(int(*request.MaxSessionDuration), 180, 600) { + c.JSON(pkg_errors.CreateAssistantApiDeploymentInvalidSessionDuration.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidSessionDuration.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentInvalidSessionDuration.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidSessionDuration.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidSessionDuration.ErrorMessage), + }, + }) + return + } + + var inputAudio *assistant_api.DeploymentAudioProvider + if validator.NonNil(request.InputAudio) { + if !validator.NotBlank(request.InputAudio.AudioProvider) { + c.JSON(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.ErrorMessage), + }, + }) + return + } + inputAudioOptions := []*assistant_api.Metadata{} + if validator.NonNil(request.InputAudio.AudioOptions) { + for _, audioOption := range *request.InputAudio.AudioOptions { + key := "" + if validator.NonNil(audioOption.Key) { + key = *audioOption.Key + } + value := "" + if validator.NonNil(audioOption.Value) { + value = *audioOption.Value + } + inputAudioOptions = append(inputAudioOptions, &assistant_api.Metadata{Key: key, Value: value}) + } + } + inputAudioStatus := "" + if validator.NonNil(request.InputAudio.Status) { + inputAudioStatus = *request.InputAudio.Status + } + inputAudioType := "" + if validator.NonNil(request.InputAudio.AudioType) { + inputAudioType = *request.InputAudio.AudioType + } + inputAudio = &assistant_api.DeploymentAudioProvider{ + AudioProvider: request.InputAudio.AudioProvider, + AudioOptions: inputAudioOptions, + Status: inputAudioStatus, + AudioType: inputAudioType, + } + } + + var outputAudio *assistant_api.DeploymentAudioProvider + if validator.NonNil(request.OutputAudio) { + if !validator.NotBlank(request.OutputAudio.AudioProvider) { + c.JSON(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.ErrorMessage), + }, + }) + return + } + outputAudioOptions := []*assistant_api.Metadata{} + if validator.NonNil(request.OutputAudio.AudioOptions) { + for _, audioOption := range *request.OutputAudio.AudioOptions { + key := "" + if validator.NonNil(audioOption.Key) { + key = *audioOption.Key + } + value := "" + if validator.NonNil(audioOption.Value) { + value = *audioOption.Value + } + outputAudioOptions = append(outputAudioOptions, &assistant_api.Metadata{Key: key, Value: value}) + } + } + outputAudioStatus := "" + if validator.NonNil(request.OutputAudio.Status) { + outputAudioStatus = *request.OutputAudio.Status + } + outputAudioType := "" + if validator.NonNil(request.OutputAudio.AudioType) { + outputAudioType = *request.OutputAudio.AudioType + } + outputAudio = &assistant_api.DeploymentAudioProvider{ + AudioProvider: request.OutputAudio.AudioProvider, + AudioOptions: outputAudioOptions, + Status: outputAudioStatus, + AudioType: outputAudioType, + } + } + + deployment, err := deploymentApi.deploymentService.CreateApiDeployment( + c, + auth, + assistantId, + request.Greeting, + request.Mistake, + request.IdealTimeout, + request.IdealTimeoutBackoff, + request.IdealTimeoutMessage, + request.MaxSessionDuration, + inputAudio, + outputAudio, + ) + if err != nil { + deploymentApi.logger.Errorf("unable to create assistant api deployment: %v", err) + c.JSON(pkg_errors.CreateAssistantApiDeploymentCreateDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentCreateDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantApiDeploymentCreateDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentCreateDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantApiDeploymentCreateDeployment.ErrorMessage), + }, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + + c.JSON(http.StatusOK, openapi.GetAssistantApiDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantApiDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/create_assistant_debugger_deployment_rest_test.go b/api/assistant-api/api/assistant-deployment/create_assistant_debugger_deployment_rest_test.go index 0d620d00..04a438bf 100644 --- a/api/assistant-api/api/assistant-deployment/create_assistant_debugger_deployment_rest_test.go +++ b/api/assistant-api/api/assistant-deployment/create_assistant_debugger_deployment_rest_test.go @@ -14,6 +14,7 @@ import ( internal_services "github.com/rapidaai/api/assistant-api/internal/services" "github.com/rapidaai/pkg/commons" pkg_errors "github.com/rapidaai/pkg/errors" + gorm_types "github.com/rapidaai/pkg/models/gorm/types" "github.com/rapidaai/pkg/types" type_enums "github.com/rapidaai/pkg/types/enums" "github.com/rapidaai/protos" @@ -24,60 +25,161 @@ import ( type createDebuggerDeploymentRestServiceStub struct { createCalled bool createErr error + getCalled bool + getErr error + getNil bool + getAllCalled bool + getAllErr error + page uint32 + pageSize uint32 + criterias []*protos.Criteria assistantId uint64 greeting *string inputAudio *protos.DeploymentAudioProvider + outputAudio *protos.DeploymentAudioProvider maxSessionDuration *uint64 + suggestion []string + phoneProviderName string + phoneOptions []*protos.Metadata + whatsappProvider string + whatsappOptions []*protos.Metadata } func (s *createDebuggerDeploymentRestServiceStub) CreateWhatsappDeployment( - context.Context, - types.SimplePrinciple, - uint64, - *string, - *string, - *uint64, - *uint64, - *string, - *uint64, - string, - []*protos.Metadata, + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + greeting *string, + mistake *string, + idealTimeout *uint64, + idealTimeoutBackoff *uint64, + idealTimeoutMessage *string, + maxSessionDuration *uint64, + whatsappProvider string, + whatsappOptions []*protos.Metadata, ) (*internal_assistant_entity.AssistantWhatsappDeployment, error) { - return nil, errors.New("not implemented") + _, _, _ = mistake, idealTimeoutBackoff, idealTimeoutMessage + s.createCalled = true + s.assistantId = assistantId + s.greeting = greeting + s.maxSessionDuration = maxSessionDuration + s.whatsappProvider = whatsappProvider + s.whatsappOptions = whatsappOptions + if s.createErr != nil { + return nil, s.createErr + } + + whatsappDeployment := &internal_assistant_entity.AssistantWhatsappDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: greeting, + IdleTimeout: idealTimeout, + MaxSessionDuration: maxSessionDuration, + }, + AssistantDeploymentWhatsapp: internal_assistant_entity.AssistantDeploymentWhatsapp{ + WhatsappProvider: whatsappProvider, + }, + } + for _, option := range whatsappOptions { + optionEntity := &internal_assistant_entity.AssistantDeploymentWhatsappOption{} + optionEntity.Key = option.GetKey() + optionEntity.Value = option.GetValue() + whatsappDeployment.WhatsappOptions = append(whatsappDeployment.WhatsappOptions, optionEntity) + } + return whatsappDeployment, nil } func (s *createDebuggerDeploymentRestServiceStub) CreatePhoneDeployment( - context.Context, - types.SimplePrinciple, - uint64, - *string, - *string, - *uint64, - *uint64, - *string, - *uint64, - string, - *protos.DeploymentAudioProvider, - *protos.DeploymentAudioProvider, - []*protos.Metadata, + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + greeting *string, + mistake *string, + idealTimeout *uint64, + idealTimeoutBackoff *uint64, + idealTimeoutMessage *string, + maxSessionDuration *uint64, + phoneProviderName string, + inputAudio *protos.DeploymentAudioProvider, + outputAudio *protos.DeploymentAudioProvider, + phoneOptions []*protos.Metadata, ) (*internal_assistant_entity.AssistantPhoneDeployment, error) { - return nil, errors.New("not implemented") + _, _, _, _, _ = mistake, idealTimeout, idealTimeoutBackoff, idealTimeoutMessage, outputAudio + s.createCalled = true + s.assistantId = assistantId + s.greeting = greeting + s.inputAudio = inputAudio + s.outputAudio = outputAudio + s.maxSessionDuration = maxSessionDuration + s.phoneProviderName = phoneProviderName + s.phoneOptions = phoneOptions + if s.createErr != nil { + return nil, s.createErr + } + + inputAudioEntity := deploymentAudioProviderEntityFromProto(inputAudio) + phoneDeployment := &internal_assistant_entity.AssistantPhoneDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: greeting, + MaxSessionDuration: maxSessionDuration, + }, + AssistantDeploymentTelephony: internal_assistant_entity.AssistantDeploymentTelephony{ + TelephonyProvider: phoneProviderName, + }, + InputAudio: inputAudioEntity, + } + for _, option := range phoneOptions { + optionEntity := &internal_assistant_entity.AssistantDeploymentTelephonyOption{} + optionEntity.Key = option.GetKey() + optionEntity.Value = option.GetValue() + phoneDeployment.TelephonyOption = append(phoneDeployment.TelephonyOption, optionEntity) + } + return phoneDeployment, nil } func (s *createDebuggerDeploymentRestServiceStub) CreateApiDeployment( - context.Context, - types.SimplePrinciple, - uint64, - *string, - *string, - *uint64, - *uint64, - *string, - *uint64, - *protos.DeploymentAudioProvider, - *protos.DeploymentAudioProvider, + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + greeting *string, + mistake *string, + idealTimeout *uint64, + idealTimeoutBackoff *uint64, + idealTimeoutMessage *string, + maxSessionDuration *uint64, + inputAudio *protos.DeploymentAudioProvider, + outputAudio *protos.DeploymentAudioProvider, ) (*internal_assistant_entity.AssistantApiDeployment, error) { - return nil, errors.New("not implemented") + _, _, _ = mistake, idealTimeoutBackoff, idealTimeoutMessage + s.createCalled = true + s.assistantId = assistantId + s.greeting = greeting + s.inputAudio = inputAudio + s.outputAudio = outputAudio + s.maxSessionDuration = maxSessionDuration + if s.createErr != nil { + return nil, s.createErr + } + + inputAudioEntity := deploymentAudioProviderEntityFromProto(inputAudio) + outputAudioEntity := deploymentAudioProviderEntityFromProto(outputAudio) + return &internal_assistant_entity.AssistantApiDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: greeting, + IdleTimeout: idealTimeout, + MaxSessionDuration: maxSessionDuration, + }, + InputAudio: inputAudioEntity, + OutputAudio: outputAudioEntity, + }, nil } func (s *createDebuggerDeploymentRestServiceStub) CreateDebuggerDeployment( @@ -95,6 +197,7 @@ func (s *createDebuggerDeploymentRestServiceStub) CreateDebuggerDeployment( s.assistantId = assistantId s.greeting = greeting s.inputAudio = inputAudio + s.outputAudio = nil s.maxSessionDuration = maxSessionDuration if s.createErr != nil { return nil, s.createErr @@ -115,60 +218,317 @@ func (s *createDebuggerDeploymentRestServiceStub) CreateDebuggerDeployment( } func (s *createDebuggerDeploymentRestServiceStub) CreateWebPluginDeployment( - context.Context, - types.SimplePrinciple, - uint64, - *string, - *string, - *uint64, - *uint64, - *string, - *uint64, - []string, - *protos.DeploymentAudioProvider, - *protos.DeploymentAudioProvider, + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + greeting *string, + mistake *string, + idealTimeout *uint64, + idealTimeoutBackoff *uint64, + idealTimeoutMessage *string, + maxSessionDuration *uint64, + suggestion []string, + inputAudio *protos.DeploymentAudioProvider, + outputAudio *protos.DeploymentAudioProvider, ) (*internal_assistant_entity.AssistantWebPluginDeployment, error) { - return nil, errors.New("not implemented") + _, _, _ = mistake, idealTimeoutBackoff, idealTimeoutMessage + s.createCalled = true + s.assistantId = assistantId + s.greeting = greeting + s.inputAudio = inputAudio + s.outputAudio = outputAudio + s.maxSessionDuration = maxSessionDuration + s.suggestion = suggestion + if s.createErr != nil { + return nil, s.createErr + } + + inputAudioEntity := deploymentAudioProviderEntityFromProto(inputAudio) + outputAudioEntity := deploymentAudioProviderEntityFromProto(outputAudio) + return &internal_assistant_entity.AssistantWebPluginDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: greeting, + IdleTimeout: idealTimeout, + MaxSessionDuration: maxSessionDuration, + }, + Suggestion: gorm_types.StringArray(suggestion), + InputAudio: inputAudioEntity, + OutputAudio: outputAudioEntity, + }, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAssistantApiDeployment(context.Context, types.SimplePrinciple, uint64) (*internal_assistant_entity.AssistantApiDeployment, error) { - return nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAssistantApiDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, +) (*internal_assistant_entity.AssistantApiDeployment, error) { + s.getCalled = true + s.assistantId = assistantId + if s.getErr != nil { + return nil, s.getErr + } + if s.getNil { + return nil, nil + } + greeting := "Hello" + inputAudio := &internal_assistant_entity.AssistantDeploymentAudio{ + AudioType: "input", + AudioProvider: "twilio", + } + inputAudio.Id = 321 + inputAudio.Status = type_enums.RECORD_ACTIVE + inputAudioOption := &internal_assistant_entity.AssistantDeploymentAudioOption{} + inputAudioOption.Key = "codec" + inputAudioOption.Value = "mulaw" + inputAudio.AudioOptions = append(inputAudio.AudioOptions, inputAudioOption) + deployment := &internal_assistant_entity.AssistantApiDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: &greeting, + }, + InputAudio: inputAudio, + } + deployment.Id = 654 + deployment.Status = type_enums.RECORD_ACTIVE + return deployment, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAssistantDebuggerDeployment(context.Context, types.SimplePrinciple, uint64) (*internal_assistant_entity.AssistantDebuggerDeployment, error) { - return nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAssistantDebuggerDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, +) (*internal_assistant_entity.AssistantDebuggerDeployment, error) { + s.getCalled = true + s.assistantId = assistantId + if s.getErr != nil { + return nil, s.getErr + } + if s.getNil { + return nil, nil + } + greeting := "Hello" + deployment := &internal_assistant_entity.AssistantDebuggerDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: &greeting, + }, + } + deployment.Id = 655 + deployment.Status = type_enums.RECORD_ACTIVE + return deployment, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAssistantPhoneDeployment(context.Context, types.SimplePrinciple, uint64) (*internal_assistant_entity.AssistantPhoneDeployment, error) { - return nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAssistantPhoneDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, +) (*internal_assistant_entity.AssistantPhoneDeployment, error) { + s.getCalled = true + s.assistantId = assistantId + if s.getErr != nil { + return nil, s.getErr + } + if s.getNil { + return nil, nil + } + greeting := "Hello" + deployment := &internal_assistant_entity.AssistantPhoneDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: &greeting, + }, + AssistantDeploymentTelephony: internal_assistant_entity.AssistantDeploymentTelephony{ + TelephonyProvider: "twilio", + }, + } + deployment.Id = 656 + deployment.Status = type_enums.RECORD_ACTIVE + phoneOption := &internal_assistant_entity.AssistantDeploymentTelephonyOption{} + phoneOption.Key = "phone" + phoneOption.Value = "+15551234567" + deployment.TelephonyOption = append(deployment.TelephonyOption, phoneOption) + return deployment, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAssistantWebpluginDeployment(context.Context, types.SimplePrinciple, uint64) (*internal_assistant_entity.AssistantWebPluginDeployment, error) { - return nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAssistantWebpluginDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, +) (*internal_assistant_entity.AssistantWebPluginDeployment, error) { + s.getCalled = true + s.assistantId = assistantId + if s.getErr != nil { + return nil, s.getErr + } + if s.getNil { + return nil, nil + } + greeting := "Hello" + deployment := &internal_assistant_entity.AssistantWebPluginDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: &greeting, + }, + Suggestion: gorm_types.StringArray{"Book demo", "Talk to support"}, + } + deployment.Id = 657 + deployment.Status = type_enums.RECORD_ACTIVE + return deployment, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAssistantWhatsappDeployment(context.Context, types.SimplePrinciple, uint64) (*internal_assistant_entity.AssistantWhatsappDeployment, error) { - return nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAssistantWhatsappDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, +) (*internal_assistant_entity.AssistantWhatsappDeployment, error) { + s.getCalled = true + s.assistantId = assistantId + if s.getErr != nil { + return nil, s.getErr + } + if s.getNil { + return nil, nil + } + greeting := "Hello" + deployment := &internal_assistant_entity.AssistantWhatsappDeployment{ + AssistantDeploymentBehavior: internal_assistant_entity.AssistantDeploymentBehavior{ + AssistantDeployment: internal_assistant_entity.AssistantDeployment{ + AssistantId: assistantId, + }, + Greeting: &greeting, + }, + AssistantDeploymentWhatsapp: internal_assistant_entity.AssistantDeploymentWhatsapp{ + WhatsappProvider: "gupshup", + }, + } + deployment.Id = 658 + deployment.Status = type_enums.RECORD_ACTIVE + whatsappOption := &internal_assistant_entity.AssistantDeploymentWhatsappOption{} + whatsappOption.Key = "template" + whatsappOption.Value = "welcome" + deployment.WhatsappOptions = append(deployment.WhatsappOptions, whatsappOption) + return deployment, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantApiDeployment(context.Context, types.SimplePrinciple, uint64, []*protos.Criteria, *protos.Paginate) (int64, []*internal_assistant_entity.AssistantApiDeployment, error) { - return 0, nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantApiDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + criterias []*protos.Criteria, + paginate *protos.Paginate, +) (int64, []*internal_assistant_entity.AssistantApiDeployment, error) { + s.getAllCalled = true + s.assistantId = assistantId + s.criterias = criterias + s.page = paginate.GetPage() + s.pageSize = paginate.GetPageSize() + if s.getAllErr != nil { + return 0, nil, s.getAllErr + } + deployment, err := s.GetAssistantApiDeployment(context.Background(), nil, assistantId) + if err != nil { + return 0, nil, err + } + return 1, []*internal_assistant_entity.AssistantApiDeployment{deployment}, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantDebuggerDeployment(context.Context, types.SimplePrinciple, uint64, []*protos.Criteria, *protos.Paginate) (int64, []*internal_assistant_entity.AssistantDebuggerDeployment, error) { - return 0, nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantDebuggerDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + criterias []*protos.Criteria, + paginate *protos.Paginate, +) (int64, []*internal_assistant_entity.AssistantDebuggerDeployment, error) { + s.getAllCalled = true + s.assistantId = assistantId + s.criterias = criterias + s.page = paginate.GetPage() + s.pageSize = paginate.GetPageSize() + if s.getAllErr != nil { + return 0, nil, s.getAllErr + } + deployment, err := s.GetAssistantDebuggerDeployment(context.Background(), nil, assistantId) + if err != nil { + return 0, nil, err + } + return 1, []*internal_assistant_entity.AssistantDebuggerDeployment{deployment}, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantPhoneDeployment(context.Context, types.SimplePrinciple, uint64, []*protos.Criteria, *protos.Paginate) (int64, []*internal_assistant_entity.AssistantPhoneDeployment, error) { - return 0, nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantPhoneDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + criterias []*protos.Criteria, + paginate *protos.Paginate, +) (int64, []*internal_assistant_entity.AssistantPhoneDeployment, error) { + s.getAllCalled = true + s.assistantId = assistantId + s.criterias = criterias + s.page = paginate.GetPage() + s.pageSize = paginate.GetPageSize() + if s.getAllErr != nil { + return 0, nil, s.getAllErr + } + deployment, err := s.GetAssistantPhoneDeployment(context.Background(), nil, assistantId) + if err != nil { + return 0, nil, err + } + return 1, []*internal_assistant_entity.AssistantPhoneDeployment{deployment}, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantWebpluginDeployment(context.Context, types.SimplePrinciple, uint64, []*protos.Criteria, *protos.Paginate) (int64, []*internal_assistant_entity.AssistantWebPluginDeployment, error) { - return 0, nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantWebpluginDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + criterias []*protos.Criteria, + paginate *protos.Paginate, +) (int64, []*internal_assistant_entity.AssistantWebPluginDeployment, error) { + s.getAllCalled = true + s.assistantId = assistantId + s.criterias = criterias + s.page = paginate.GetPage() + s.pageSize = paginate.GetPageSize() + if s.getAllErr != nil { + return 0, nil, s.getAllErr + } + deployment, err := s.GetAssistantWebpluginDeployment(context.Background(), nil, assistantId) + if err != nil { + return 0, nil, err + } + return 1, []*internal_assistant_entity.AssistantWebPluginDeployment{deployment}, nil } -func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantWhatsappDeployment(context.Context, types.SimplePrinciple, uint64, []*protos.Criteria, *protos.Paginate) (int64, []*internal_assistant_entity.AssistantWhatsappDeployment, error) { - return 0, nil, errors.New("not implemented") +func (s *createDebuggerDeploymentRestServiceStub) GetAllAssistantWhatsappDeployment( + _ context.Context, + _ types.SimplePrinciple, + assistantId uint64, + criterias []*protos.Criteria, + paginate *protos.Paginate, +) (int64, []*internal_assistant_entity.AssistantWhatsappDeployment, error) { + s.getAllCalled = true + s.assistantId = assistantId + s.criterias = criterias + s.page = paginate.GetPage() + s.pageSize = paginate.GetPageSize() + if s.getAllErr != nil { + return 0, nil, s.getAllErr + } + deployment, err := s.GetAssistantWhatsappDeployment(context.Background(), nil, assistantId) + if err != nil { + return 0, nil, err + } + return 1, []*internal_assistant_entity.AssistantWhatsappDeployment{deployment}, nil } func (s *createDebuggerDeploymentRestServiceStub) DisableAssistantApiDeployment(context.Context, types.SimplePrinciple, uint64) (*internal_assistant_entity.AssistantApiDeployment, error) { diff --git a/api/assistant-api/api/assistant-deployment/create_assistant_phone_deployment_rest.go b/api/assistant-api/api/assistant-deployment/create_assistant_phone_deployment_rest.go new file mode 100644 index 00000000..d1037585 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/create_assistant_phone_deployment_rest.go @@ -0,0 +1,338 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) CreateAssistantPhoneDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + var request openapi.CreateAssistantPhoneDeploymentRequest + if err := c.ShouldBindJSON(&request); err != nil { + deploymentApi.logger.Errorf("create assistant phone deployment invalid request: %v", err) + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(string(request.AssistantId), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + if !validator.NotBlank(request.PhoneProviderName) { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentMissingPhoneProvider.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentMissingPhoneProvider.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentMissingPhoneProvider.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentMissingPhoneProvider.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentMissingPhoneProvider.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.IdealTimeout) && !validator.Between(int(*request.IdealTimeout), 15, 120) { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentInvalidIdealTimeout.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidIdealTimeout.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentInvalidIdealTimeout.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidIdealTimeout.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidIdealTimeout.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.IdealTimeoutBackoff) && !validator.Between(int(*request.IdealTimeoutBackoff), 0, 5) { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentInvalidTimeoutBackoff.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidTimeoutBackoff.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentInvalidTimeoutBackoff.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidTimeoutBackoff.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidTimeoutBackoff.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.MaxSessionDuration) && !validator.Between(int(*request.MaxSessionDuration), 180, 600) { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentInvalidSessionDuration.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidSessionDuration.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentInvalidSessionDuration.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidSessionDuration.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidSessionDuration.ErrorMessage), + }, + }) + return + } + + var inputAudio *assistant_api.DeploymentAudioProvider + if validator.NonNil(request.InputAudio) { + if !validator.NotBlank(request.InputAudio.AudioProvider) { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.ErrorMessage), + }, + }) + return + } + inputAudioOptions := []*assistant_api.Metadata{} + if validator.NonNil(request.InputAudio.AudioOptions) { + for _, audioOption := range *request.InputAudio.AudioOptions { + key := "" + if validator.NonNil(audioOption.Key) { + key = *audioOption.Key + } + value := "" + if validator.NonNil(audioOption.Value) { + value = *audioOption.Value + } + inputAudioOptions = append(inputAudioOptions, &assistant_api.Metadata{Key: key, Value: value}) + } + } + inputAudioStatus := "" + if validator.NonNil(request.InputAudio.Status) { + inputAudioStatus = *request.InputAudio.Status + } + inputAudioType := "" + if validator.NonNil(request.InputAudio.AudioType) { + inputAudioType = *request.InputAudio.AudioType + } + inputAudio = &assistant_api.DeploymentAudioProvider{ + AudioProvider: request.InputAudio.AudioProvider, + AudioOptions: inputAudioOptions, + Status: inputAudioStatus, + AudioType: inputAudioType, + } + } + + var outputAudio *assistant_api.DeploymentAudioProvider + if validator.NonNil(request.OutputAudio) { + if !validator.NotBlank(request.OutputAudio.AudioProvider) { + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.ErrorMessage), + }, + }) + return + } + outputAudioOptions := []*assistant_api.Metadata{} + if validator.NonNil(request.OutputAudio.AudioOptions) { + for _, audioOption := range *request.OutputAudio.AudioOptions { + key := "" + if validator.NonNil(audioOption.Key) { + key = *audioOption.Key + } + value := "" + if validator.NonNil(audioOption.Value) { + value = *audioOption.Value + } + outputAudioOptions = append(outputAudioOptions, &assistant_api.Metadata{Key: key, Value: value}) + } + } + outputAudioStatus := "" + if validator.NonNil(request.OutputAudio.Status) { + outputAudioStatus = *request.OutputAudio.Status + } + outputAudioType := "" + if validator.NonNil(request.OutputAudio.AudioType) { + outputAudioType = *request.OutputAudio.AudioType + } + outputAudio = &assistant_api.DeploymentAudioProvider{ + AudioProvider: request.OutputAudio.AudioProvider, + AudioOptions: outputAudioOptions, + Status: outputAudioStatus, + AudioType: outputAudioType, + } + } + + phoneOptions := []*assistant_api.Metadata{} + if validator.NonNil(request.PhoneOptions) { + for _, phoneOption := range *request.PhoneOptions { + key := "" + if validator.NonNil(phoneOption.Key) { + key = *phoneOption.Key + } + value := "" + if validator.NonNil(phoneOption.Value) { + value = *phoneOption.Value + } + phoneOptions = append(phoneOptions, &assistant_api.Metadata{Key: key, Value: value}) + } + } + + deployment, err := deploymentApi.deploymentService.CreatePhoneDeployment( + c, + auth, + assistantId, + request.Greeting, + request.Mistake, + request.IdealTimeout, + request.IdealTimeoutBackoff, + request.IdealTimeoutMessage, + request.MaxSessionDuration, + request.PhoneProviderName, + inputAudio, + outputAudio, + phoneOptions, + ) + if err != nil { + deploymentApi.logger.Errorf("unable to create assistant phone deployment: %v", err) + c.JSON(pkg_errors.CreateAssistantPhoneDeploymentCreateDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentCreateDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantPhoneDeploymentCreateDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentCreateDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantPhoneDeploymentCreateDeployment.ErrorMessage), + }, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + + responsePhoneOptions := []openapi.Metadata{} + for _, phoneOption := range deployment.TelephonyOption { + if !validator.NonNil(phoneOption) { + continue + } + responsePhoneOptions = append(responsePhoneOptions, openapi.Metadata{ + Key: utils.Ptr(phoneOption.Key), + Value: utils.Ptr(phoneOption.Value), + }) + } + phoneProviderName := deployment.TelephonyProvider + + c.JSON(http.StatusOK, openapi.GetAssistantPhoneDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantPhoneDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + PhoneProviderName: &phoneProviderName, + PhoneOptions: &responsePhoneOptions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/create_assistant_phone_deployment_rest_test.go b/api/assistant-api/api/assistant-deployment/create_assistant_phone_deployment_rest_test.go new file mode 100644 index 00000000..4ddf4efe --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/create_assistant_phone_deployment_rest_test.go @@ -0,0 +1,169 @@ +package assistant_deployment_api + +import ( + "bytes" + "encoding/json" + "errors" + "net/http" + "net/http/httptest" + "testing" + + "github.com/gin-gonic/gin" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestCreateAssistantPhoneDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + requestBody := []byte(`{ + "assistantId": "123", + "greeting": "Hello", + "idealTimeout": 30, + "maxSessionDuration": 600, + "phoneProviderName": "twilio", + "phoneOptions": [{"key": "phone", "value": "+15551234567"}], + "inputAudio": { + "audioProvider": "twilio", + "audioType": "input", + "audioOptions": [{"key": "codec", "value": "mulaw"}] + } + }`) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-phone-deployment", + bytes.NewReader(requestBody), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.createCalled) + assert.Equal(t, uint64(123), service.assistantId) + assert.Equal(t, "twilio", service.phoneProviderName) + require.Len(t, service.phoneOptions, 1) + assert.Equal(t, "phone", service.phoneOptions[0].GetKey()) + require.NotNil(t, service.inputAudio) + assert.Equal(t, "twilio", service.inputAudio.GetAudioProvider()) + + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, "123", data["assistantId"]) + assert.Equal(t, "twilio", data["phoneProviderName"]) +} + +func TestCreateAssistantPhoneDeploymentRest_Unauthenticated(t *testing.T) { + gin.SetMode(gin.TestMode) + deploymentApi := newCreateDebuggerDeploymentRestApi(t, &createDebuggerDeploymentRestServiceStub{}) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-phone-deployment", + bytes.NewReader([]byte(`{}`)), + ) + context.Request.Header.Set("Content-Type", "application/json") + + deploymentApi.CreateAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusUnauthorized, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.CreateAssistantPhoneDeploymentUnauthenticated.Error) +} + +func TestCreateAssistantPhoneDeploymentRest_MissingAuthScope(t *testing.T) { + gin.SetMode(gin.TestMode) + deploymentApi := newCreateDebuggerDeploymentRestApi(t, &createDebuggerDeploymentRestServiceStub{}) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-phone-deployment", + bytes.NewReader([]byte(`{"assistantId":"123","phoneProviderName":"twilio"}`)), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), &types.PlainAuthPrinciple{ + User: types.UserInfo{Id: 11}, + OrganizationRole: &types.OrganizaitonRole{OrganizationId: 22}, + }) + + deploymentApi.CreateAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusForbidden, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.CreateAssistantPhoneDeploymentMissingAuthScope.Error) +} + +func TestCreateAssistantPhoneDeploymentRest_MissingPhoneProvider(t *testing.T) { + gin.SetMode(gin.TestMode) + deploymentApi := newCreateDebuggerDeploymentRestApi(t, &createDebuggerDeploymentRestServiceStub{}) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-phone-deployment", + bytes.NewReader([]byte(`{"assistantId":"123","phoneProviderName":""}`)), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusBadRequest, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.CreateAssistantPhoneDeploymentMissingPhoneProvider.Error) +} + +func TestCreateAssistantPhoneDeploymentRest_InvalidAudioProvider(t *testing.T) { + gin.SetMode(gin.TestMode) + deploymentApi := newCreateDebuggerDeploymentRestApi(t, &createDebuggerDeploymentRestServiceStub{}) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-phone-deployment", + bytes.NewReader([]byte(`{"assistantId":"123","phoneProviderName":"twilio","inputAudio":{"audioProvider":""}}`)), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusBadRequest, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.CreateAssistantPhoneDeploymentInvalidAudioProvider.Error) +} + +func TestCreateAssistantPhoneDeploymentRest_CreateDeploymentErrorDoesNotExposeInternalError(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{ + createErr: errors.New("database password leaked"), + } + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-phone-deployment", + bytes.NewReader([]byte(`{"assistantId":"123","phoneProviderName":"twilio"}`)), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusInternalServerError, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.CreateAssistantPhoneDeploymentCreateDeployment.Error) + assert.NotContains(t, recorder.Body.String(), "database password leaked") +} diff --git a/api/assistant-api/api/assistant-deployment/create_assistant_webplugin_deployment_rest.go b/api/assistant-api/api/assistant-deployment/create_assistant_webplugin_deployment_rest.go new file mode 100644 index 00000000..f2f10271 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/create_assistant_webplugin_deployment_rest.go @@ -0,0 +1,302 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) CreateAssistantWebpluginDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + var request openapi.CreateAssistantWebpluginDeploymentRequest + if err := c.ShouldBindJSON(&request); err != nil { + deploymentApi.logger.Errorf("create assistant webplugin deployment invalid request: %v", err) + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(string(request.AssistantId), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.IdealTimeout) && !validator.Between(int(*request.IdealTimeout), 15, 120) { + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentInvalidIdealTimeout.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidIdealTimeout.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentInvalidIdealTimeout.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidIdealTimeout.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidIdealTimeout.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.IdealTimeoutBackoff) && !validator.Between(int(*request.IdealTimeoutBackoff), 0, 5) { + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentInvalidTimeoutBackoff.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidTimeoutBackoff.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentInvalidTimeoutBackoff.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidTimeoutBackoff.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidTimeoutBackoff.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.MaxSessionDuration) && !validator.Between(int(*request.MaxSessionDuration), 180, 600) { + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentInvalidSessionDuration.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidSessionDuration.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentInvalidSessionDuration.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidSessionDuration.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidSessionDuration.ErrorMessage), + }, + }) + return + } + + var inputAudio *assistant_api.DeploymentAudioProvider + if validator.NonNil(request.InputAudio) { + if !validator.NotBlank(request.InputAudio.AudioProvider) { + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.ErrorMessage), + }, + }) + return + } + inputAudioOptions := []*assistant_api.Metadata{} + if validator.NonNil(request.InputAudio.AudioOptions) { + for _, audioOption := range *request.InputAudio.AudioOptions { + key := "" + if validator.NonNil(audioOption.Key) { + key = *audioOption.Key + } + value := "" + if validator.NonNil(audioOption.Value) { + value = *audioOption.Value + } + inputAudioOptions = append(inputAudioOptions, &assistant_api.Metadata{Key: key, Value: value}) + } + } + inputAudioStatus := "" + if validator.NonNil(request.InputAudio.Status) { + inputAudioStatus = *request.InputAudio.Status + } + inputAudioType := "" + if validator.NonNil(request.InputAudio.AudioType) { + inputAudioType = *request.InputAudio.AudioType + } + inputAudio = &assistant_api.DeploymentAudioProvider{ + AudioProvider: request.InputAudio.AudioProvider, + AudioOptions: inputAudioOptions, + Status: inputAudioStatus, + AudioType: inputAudioType, + } + } + + var outputAudio *assistant_api.DeploymentAudioProvider + if validator.NonNil(request.OutputAudio) { + if !validator.NotBlank(request.OutputAudio.AudioProvider) { + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentInvalidAudioProvider.ErrorMessage), + }, + }) + return + } + outputAudioOptions := []*assistant_api.Metadata{} + if validator.NonNil(request.OutputAudio.AudioOptions) { + for _, audioOption := range *request.OutputAudio.AudioOptions { + key := "" + if validator.NonNil(audioOption.Key) { + key = *audioOption.Key + } + value := "" + if validator.NonNil(audioOption.Value) { + value = *audioOption.Value + } + outputAudioOptions = append(outputAudioOptions, &assistant_api.Metadata{Key: key, Value: value}) + } + } + outputAudioStatus := "" + if validator.NonNil(request.OutputAudio.Status) { + outputAudioStatus = *request.OutputAudio.Status + } + outputAudioType := "" + if validator.NonNil(request.OutputAudio.AudioType) { + outputAudioType = *request.OutputAudio.AudioType + } + outputAudio = &assistant_api.DeploymentAudioProvider{ + AudioProvider: request.OutputAudio.AudioProvider, + AudioOptions: outputAudioOptions, + Status: outputAudioStatus, + AudioType: outputAudioType, + } + } + + suggestions := []string{} + if validator.NonNil(request.Suggestion) { + suggestions = *request.Suggestion + } + deployment, err := deploymentApi.deploymentService.CreateWebPluginDeployment( + c, + auth, + assistantId, + request.Greeting, + request.Mistake, + request.IdealTimeout, + request.IdealTimeoutBackoff, + request.IdealTimeoutMessage, + request.MaxSessionDuration, + suggestions, + inputAudio, + outputAudio, + ) + if err != nil { + deploymentApi.logger.Errorf("unable to create assistant webplugin deployment: %v", err) + c.JSON(pkg_errors.CreateAssistantWebpluginDeploymentCreateDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentCreateDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWebpluginDeploymentCreateDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentCreateDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWebpluginDeploymentCreateDeployment.ErrorMessage), + }, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + responseSuggestions := []string(deployment.Suggestion) + + c.JSON(http.StatusOK, openapi.GetAssistantWebpluginDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantWebpluginDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + Suggestion: &responseSuggestions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/create_assistant_whatsapp_deployment_rest.go b/api/assistant-api/api/assistant-deployment/create_assistant_whatsapp_deployment_rest.go new file mode 100644 index 00000000..42c126ac --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/create_assistant_whatsapp_deployment_rest.go @@ -0,0 +1,200 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) CreateAssistantWhatsappDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + var request openapi.CreateAssistantWhatsappDeploymentRequest + if err := c.ShouldBindJSON(&request); err != nil { + deploymentApi.logger.Errorf("create assistant whatsapp deployment invalid request: %v", err) + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(string(request.AssistantId), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + if !validator.NotBlank(request.WhatsappProviderName) { + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentMissingProvider.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentMissingProvider.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentMissingProvider.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentMissingProvider.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentMissingProvider.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.IdealTimeout) && !validator.Between(int(*request.IdealTimeout), 15, 120) { + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentInvalidIdealTimeout.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidIdealTimeout.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentInvalidIdealTimeout.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidIdealTimeout.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidIdealTimeout.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.IdealTimeoutBackoff) && !validator.Between(int(*request.IdealTimeoutBackoff), 0, 5) { + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentInvalidTimeoutBackoff.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidTimeoutBackoff.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentInvalidTimeoutBackoff.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidTimeoutBackoff.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidTimeoutBackoff.ErrorMessage), + }, + }) + return + } + if validator.NonNil(request.MaxSessionDuration) && !validator.Between(int(*request.MaxSessionDuration), 180, 600) { + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentInvalidSessionDuration.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidSessionDuration.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentInvalidSessionDuration.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidSessionDuration.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentInvalidSessionDuration.ErrorMessage), + }, + }) + return + } + + whatsappOptions := []*assistant_api.Metadata{} + if validator.NonNil(request.WhatsappOptions) { + for _, whatsappOption := range *request.WhatsappOptions { + key := "" + if validator.NonNil(whatsappOption.Key) { + key = *whatsappOption.Key + } + value := "" + if validator.NonNil(whatsappOption.Value) { + value = *whatsappOption.Value + } + whatsappOptions = append(whatsappOptions, &assistant_api.Metadata{Key: key, Value: value}) + } + } + + deployment, err := deploymentApi.deploymentService.CreateWhatsappDeployment( + c, + auth, + assistantId, + request.Greeting, + request.Mistake, + request.IdealTimeout, + request.IdealTimeoutBackoff, + request.IdealTimeoutMessage, + request.MaxSessionDuration, + request.WhatsappProviderName, + whatsappOptions, + ) + if err != nil { + deploymentApi.logger.Errorf("unable to create assistant whatsapp deployment: %v", err) + c.JSON(pkg_errors.CreateAssistantWhatsappDeploymentCreateDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentCreateDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.CreateAssistantWhatsappDeploymentCreateDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentCreateDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.CreateAssistantWhatsappDeploymentCreateDeployment.ErrorMessage), + }, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + responseWhatsappOptions := []openapi.Metadata{} + for _, whatsappOption := range deployment.WhatsappOptions { + if !validator.NonNil(whatsappOption) { + continue + } + responseWhatsappOptions = append(responseWhatsappOptions, openapi.Metadata{ + Key: utils.Ptr(whatsappOption.Key), + Value: utils.Ptr(whatsappOption.Value), + }) + } + whatsappProviderName := deployment.WhatsappProvider + + c.JSON(http.StatusOK, openapi.GetAssistantWhatsappDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantWhatsappDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + WhatsappProviderName: &whatsappProviderName, + WhatsappOptions: &responseWhatsappOptions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/create_other_deployments_rest_test.go b/api/assistant-api/api/assistant-deployment/create_other_deployments_rest_test.go new file mode 100644 index 00000000..5a351409 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/create_other_deployments_rest_test.go @@ -0,0 +1,210 @@ +package assistant_deployment_api + +import ( + "bytes" + "encoding/json" + "errors" + "net/http" + "net/http/httptest" + "testing" + + "github.com/gin-gonic/gin" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestCreateAssistantApiDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + requestBody := []byte(`{ + "assistantId": "123", + "greeting": "Hello", + "idealTimeout": 30, + "maxSessionDuration": 600, + "inputAudio": { + "audioProvider": "twilio", + "audioType": "input", + "audioOptions": [{"key": "codec", "value": "mulaw"}] + }, + "outputAudio": { + "audioProvider": "openai", + "audioType": "output" + } + }`) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-api-deployment", + bytes.NewReader(requestBody), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantApiDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.createCalled) + assert.Equal(t, uint64(123), service.assistantId) + require.NotNil(t, service.inputAudio) + assert.Equal(t, "twilio", service.inputAudio.GetAudioProvider()) + require.NotNil(t, service.outputAudio) + assert.Equal(t, "openai", service.outputAudio.GetAudioProvider()) + + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, "123", data["assistantId"]) +} + +func TestCreateAssistantApiDeploymentRest_InvalidAudioProvider(t *testing.T) { + gin.SetMode(gin.TestMode) + deploymentApi := newCreateDebuggerDeploymentRestApi(t, &createDebuggerDeploymentRestServiceStub{}) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-api-deployment", + bytes.NewReader([]byte(`{"assistantId":"123","outputAudio":{"audioProvider":""}}`)), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantApiDeploymentRest(context) + + require.Equal(t, http.StatusBadRequest, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.CreateAssistantApiDeploymentInvalidAudioProvider.Error) +} + +func TestCreateAssistantWebpluginDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + requestBody := []byte(`{ + "assistantId": "123", + "greeting": "Hello", + "idealTimeout": 30, + "maxSessionDuration": 600, + "suggestion": ["Book demo", "Talk to support"], + "inputAudio": { + "audioProvider": "browser", + "audioType": "input" + } + }`) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-webplugin-deployment", + bytes.NewReader(requestBody), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantWebpluginDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.createCalled) + assert.Equal(t, uint64(123), service.assistantId) + assert.Equal(t, []string{"Book demo", "Talk to support"}, service.suggestion) + require.NotNil(t, service.inputAudio) + assert.Equal(t, "browser", service.inputAudio.GetAudioProvider()) + + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, "123", data["assistantId"]) + assert.Equal(t, []interface{}{"Book demo", "Talk to support"}, data["suggestion"]) +} + +func TestCreateAssistantWebpluginDeploymentRest_CreateDeploymentErrorDoesNotExposeInternalError(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{ + createErr: errors.New("database password leaked"), + } + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-webplugin-deployment", + bytes.NewReader([]byte(`{"assistantId":"123"}`)), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantWebpluginDeploymentRest(context) + + require.Equal(t, http.StatusInternalServerError, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.CreateAssistantWebpluginDeploymentCreateDeployment.Error) + assert.NotContains(t, recorder.Body.String(), "database password leaked") +} + +func TestCreateAssistantWhatsappDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + requestBody := []byte(`{ + "assistantId": "123", + "greeting": "Hello", + "idealTimeout": 30, + "maxSessionDuration": 600, + "whatsappProviderName": "gupshup", + "whatsappOptions": [{"key": "template", "value": "welcome"}] + }`) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-whatsapp-deployment", + bytes.NewReader(requestBody), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantWhatsappDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.createCalled) + assert.Equal(t, uint64(123), service.assistantId) + assert.Equal(t, "gupshup", service.whatsappProvider) + require.Len(t, service.whatsappOptions, 1) + assert.Equal(t, "template", service.whatsappOptions[0].GetKey()) + + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, "123", data["assistantId"]) + assert.Equal(t, "gupshup", data["whatsappProviderName"]) +} + +func TestCreateAssistantWhatsappDeploymentRest_MissingWhatsappProvider(t *testing.T) { + gin.SetMode(gin.TestMode) + deploymentApi := newCreateDebuggerDeploymentRestApi(t, &createDebuggerDeploymentRestServiceStub{}) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodPost, + "/v1/assistant-deployment/create-whatsapp-deployment", + bytes.NewReader([]byte(`{"assistantId":"123","whatsappProviderName":""}`)), + ) + context.Request.Header.Set("Content-Type", "application/json") + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.CreateAssistantWhatsappDeploymentRest(context) + + require.Equal(t, http.StatusBadRequest, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.CreateAssistantWhatsappDeploymentMissingProvider.Error) +} diff --git a/api/assistant-api/api/assistant-deployment/get_all_assistant_api_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_all_assistant_api_deployment_rest.go new file mode 100644 index 00000000..12bf1461 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_all_assistant_api_deployment_rest.go @@ -0,0 +1,223 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "encoding/json" + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) GetAllAssistantApiDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAllAssistantApiDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantApiDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAllAssistantApiDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantApiDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAllAssistantApiDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantApiDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + paginate := &assistant_api.Paginate{Page: 1, PageSize: 20} + if c.Query("page") != "" { + page, err := strconv.ParseUint(c.Query("page"), 10, 32) + if err != nil || page == 0 { + c.JSON(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.Page = uint32(page) + } + if c.Query("pageSize") != "" { + pageSize, err := strconv.ParseUint(c.Query("pageSize"), 10, 32) + if err != nil || pageSize == 0 { + c.JSON(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.PageSize = uint32(pageSize) + } + + criterias := []*assistant_api.Criteria{} + if c.Query("criterias") != "" { + requestCriterias := []openapi.Criteria{} + if err := json.Unmarshal([]byte(c.Query("criterias")), &requestCriterias); err != nil { + c.JSON(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + for _, criteria := range requestCriterias { + key := "" + if validator.NonNil(criteria.Key) { + key = *criteria.Key + } + value := "" + if validator.NonNil(criteria.Value) { + value = *criteria.Value + } + logic := "" + if validator.NonNil(criteria.Logic) { + logic = *criteria.Logic + } + criterias = append(criterias, &assistant_api.Criteria{Key: key, Value: value, Logic: logic}) + } + } + + totalItems, deployments, err := deploymentApi.deploymentService.GetAllAssistantApiDeployment(c, auth, assistantId, criterias, paginate) + if err != nil { + deploymentApi.logger.Errorf("unable to get all assistant api deployments: %v", err) + c.JSON(pkg_errors.GetAllAssistantApiDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantApiDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantApiDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + + responseDeployments := []openapi.AssistantApiDeployment{} + for _, deployment := range deployments { + if !validator.NonNil(deployment) { + continue + } + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + responseDeployments = append(responseDeployments, openapi.AssistantApiDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }) + } + totalItem := uint32(totalItems) + currentPage := paginate.GetPage() + c.JSON(http.StatusOK, openapi.GetAllAssistantApiDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &responseDeployments, + Paginated: &openapi.Paginated{ + TotalItem: &totalItem, + CurrentPage: ¤tPage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_all_assistant_debugger_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_all_assistant_debugger_deployment_rest.go new file mode 100644 index 00000000..a51fa2ee --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_all_assistant_debugger_deployment_rest.go @@ -0,0 +1,223 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "encoding/json" + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) GetAllAssistantDebuggerDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAllAssistantDebuggerDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantDebuggerDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAllAssistantDebuggerDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantDebuggerDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + paginate := &assistant_api.Paginate{Page: 1, PageSize: 20} + if c.Query("page") != "" { + page, err := strconv.ParseUint(c.Query("page"), 10, 32) + if err != nil || page == 0 { + c.JSON(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.Page = uint32(page) + } + if c.Query("pageSize") != "" { + pageSize, err := strconv.ParseUint(c.Query("pageSize"), 10, 32) + if err != nil || pageSize == 0 { + c.JSON(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.PageSize = uint32(pageSize) + } + + criterias := []*assistant_api.Criteria{} + if c.Query("criterias") != "" { + requestCriterias := []openapi.Criteria{} + if err := json.Unmarshal([]byte(c.Query("criterias")), &requestCriterias); err != nil { + c.JSON(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + for _, criteria := range requestCriterias { + key := "" + if validator.NonNil(criteria.Key) { + key = *criteria.Key + } + value := "" + if validator.NonNil(criteria.Value) { + value = *criteria.Value + } + logic := "" + if validator.NonNil(criteria.Logic) { + logic = *criteria.Logic + } + criterias = append(criterias, &assistant_api.Criteria{Key: key, Value: value, Logic: logic}) + } + } + + totalItems, deployments, err := deploymentApi.deploymentService.GetAllAssistantDebuggerDeployment(c, auth, assistantId, criterias, paginate) + if err != nil { + deploymentApi.logger.Errorf("unable to get all assistant debugger deployments: %v", err) + c.JSON(pkg_errors.GetAllAssistantDebuggerDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantDebuggerDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantDebuggerDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + + responseDeployments := []openapi.AssistantDebuggerDeployment{} + for _, deployment := range deployments { + if !validator.NonNil(deployment) { + continue + } + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + responseDeployments = append(responseDeployments, openapi.AssistantDebuggerDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }) + } + totalItem := uint32(totalItems) + currentPage := paginate.GetPage() + c.JSON(http.StatusOK, openapi.GetAllAssistantDebuggerDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &responseDeployments, + Paginated: &openapi.Paginated{ + TotalItem: &totalItem, + CurrentPage: ¤tPage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_all_assistant_phone_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_all_assistant_phone_deployment_rest.go new file mode 100644 index 00000000..5cc31603 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_all_assistant_phone_deployment_rest.go @@ -0,0 +1,236 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "encoding/json" + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) GetAllAssistantPhoneDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAllAssistantPhoneDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantPhoneDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAllAssistantPhoneDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantPhoneDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAllAssistantPhoneDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantPhoneDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + paginate := &assistant_api.Paginate{Page: 1, PageSize: 20} + if c.Query("page") != "" { + page, err := strconv.ParseUint(c.Query("page"), 10, 32) + if err != nil || page == 0 { + c.JSON(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.Page = uint32(page) + } + if c.Query("pageSize") != "" { + pageSize, err := strconv.ParseUint(c.Query("pageSize"), 10, 32) + if err != nil || pageSize == 0 { + c.JSON(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.PageSize = uint32(pageSize) + } + + criterias := []*assistant_api.Criteria{} + if c.Query("criterias") != "" { + requestCriterias := []openapi.Criteria{} + if err := json.Unmarshal([]byte(c.Query("criterias")), &requestCriterias); err != nil { + c.JSON(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + for _, criteria := range requestCriterias { + key := "" + if validator.NonNil(criteria.Key) { + key = *criteria.Key + } + value := "" + if validator.NonNil(criteria.Value) { + value = *criteria.Value + } + logic := "" + if validator.NonNil(criteria.Logic) { + logic = *criteria.Logic + } + criterias = append(criterias, &assistant_api.Criteria{Key: key, Value: value, Logic: logic}) + } + } + + totalItems, deployments, err := deploymentApi.deploymentService.GetAllAssistantPhoneDeployment(c, auth, assistantId, criterias, paginate) + if err != nil { + deploymentApi.logger.Errorf("unable to get all assistant phone deployments: %v", err) + c.JSON(pkg_errors.GetAllAssistantPhoneDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantPhoneDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantPhoneDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + + responseDeployments := []openapi.AssistantPhoneDeployment{} + for _, deployment := range deployments { + if !validator.NonNil(deployment) { + continue + } + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + responsePhoneOptions := []openapi.Metadata{} + for _, phoneOption := range deployment.TelephonyOption { + if !validator.NonNil(phoneOption) { + continue + } + responsePhoneOptions = append(responsePhoneOptions, openapi.Metadata{ + Key: utils.Ptr(phoneOption.Key), + Value: utils.Ptr(phoneOption.Value), + }) + } + phoneProviderName := deployment.TelephonyProvider + responseDeployments = append(responseDeployments, openapi.AssistantPhoneDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + PhoneProviderName: &phoneProviderName, + PhoneOptions: &responsePhoneOptions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }) + } + totalItem := uint32(totalItems) + currentPage := paginate.GetPage() + c.JSON(http.StatusOK, openapi.GetAllAssistantPhoneDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &responseDeployments, + Paginated: &openapi.Paginated{ + TotalItem: &totalItem, + CurrentPage: ¤tPage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_all_assistant_webplugin_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_all_assistant_webplugin_deployment_rest.go new file mode 100644 index 00000000..b67cb7cb --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_all_assistant_webplugin_deployment_rest.go @@ -0,0 +1,225 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "encoding/json" + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) GetAllAssistantWebpluginDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAllAssistantWebpluginDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWebpluginDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAllAssistantWebpluginDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWebpluginDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + paginate := &assistant_api.Paginate{Page: 1, PageSize: 20} + if c.Query("page") != "" { + page, err := strconv.ParseUint(c.Query("page"), 10, 32) + if err != nil || page == 0 { + c.JSON(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.Page = uint32(page) + } + if c.Query("pageSize") != "" { + pageSize, err := strconv.ParseUint(c.Query("pageSize"), 10, 32) + if err != nil || pageSize == 0 { + c.JSON(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.PageSize = uint32(pageSize) + } + + criterias := []*assistant_api.Criteria{} + if c.Query("criterias") != "" { + requestCriterias := []openapi.Criteria{} + if err := json.Unmarshal([]byte(c.Query("criterias")), &requestCriterias); err != nil { + c.JSON(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + for _, criteria := range requestCriterias { + key := "" + if validator.NonNil(criteria.Key) { + key = *criteria.Key + } + value := "" + if validator.NonNil(criteria.Value) { + value = *criteria.Value + } + logic := "" + if validator.NonNil(criteria.Logic) { + logic = *criteria.Logic + } + criterias = append(criterias, &assistant_api.Criteria{Key: key, Value: value, Logic: logic}) + } + } + + totalItems, deployments, err := deploymentApi.deploymentService.GetAllAssistantWebpluginDeployment(c, auth, assistantId, criterias, paginate) + if err != nil { + deploymentApi.logger.Errorf("unable to get all assistant webplugin deployments: %v", err) + c.JSON(pkg_errors.GetAllAssistantWebpluginDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWebpluginDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWebpluginDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + + responseDeployments := []openapi.AssistantWebpluginDeployment{} + for _, deployment := range deployments { + if !validator.NonNil(deployment) { + continue + } + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + responseSuggestions := []string(deployment.Suggestion) + responseDeployments = append(responseDeployments, openapi.AssistantWebpluginDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + Suggestion: &responseSuggestions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }) + } + totalItem := uint32(totalItems) + currentPage := paginate.GetPage() + c.JSON(http.StatusOK, openapi.GetAllAssistantWebpluginDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &responseDeployments, + Paginated: &openapi.Paginated{ + TotalItem: &totalItem, + CurrentPage: ¤tPage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_all_assistant_whatsapp_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_all_assistant_whatsapp_deployment_rest.go new file mode 100644 index 00000000..2b314eb0 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_all_assistant_whatsapp_deployment_rest.go @@ -0,0 +1,188 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "encoding/json" + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" + assistant_api "github.com/rapidaai/protos" +) + +func (deploymentApi *AssistantDeploymentApi) GetAllAssistantWhatsappDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAllAssistantWhatsappDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWhatsappDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAllAssistantWhatsappDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWhatsappDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + paginate := &assistant_api.Paginate{Page: 1, PageSize: 20} + if c.Query("page") != "" { + page, err := strconv.ParseUint(c.Query("page"), 10, 32) + if err != nil || page == 0 { + c.JSON(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.Page = uint32(page) + } + if c.Query("pageSize") != "" { + pageSize, err := strconv.ParseUint(c.Query("pageSize"), 10, 32) + if err != nil || pageSize == 0 { + c.JSON(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + paginate.PageSize = uint32(pageSize) + } + + criterias := []*assistant_api.Criteria{} + if c.Query("criterias") != "" { + requestCriterias := []openapi.Criteria{} + if err := json.Unmarshal([]byte(c.Query("criterias")), &requestCriterias); err != nil { + c.JSON(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentInvalidRequest.ErrorMessage), + }, + }) + return + } + for _, criteria := range requestCriterias { + key := "" + if validator.NonNil(criteria.Key) { + key = *criteria.Key + } + value := "" + if validator.NonNil(criteria.Value) { + value = *criteria.Value + } + logic := "" + if validator.NonNil(criteria.Logic) { + logic = *criteria.Logic + } + criterias = append(criterias, &assistant_api.Criteria{Key: key, Value: value, Logic: logic}) + } + } + + totalItems, deployments, err := deploymentApi.deploymentService.GetAllAssistantWhatsappDeployment(c, auth, assistantId, criterias, paginate) + if err != nil { + deploymentApi.logger.Errorf("unable to get all assistant whatsapp deployments: %v", err) + c.JSON(pkg_errors.GetAllAssistantWhatsappDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAllAssistantWhatsappDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAllAssistantWhatsappDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + + responseDeployments := []openapi.AssistantWhatsappDeployment{} + for _, deployment := range deployments { + if !validator.NonNil(deployment) { + continue + } + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + responseWhatsappOptions := []openapi.Metadata{} + for _, whatsappOption := range deployment.WhatsappOptions { + if !validator.NonNil(whatsappOption) { + continue + } + responseWhatsappOptions = append(responseWhatsappOptions, openapi.Metadata{ + Key: utils.Ptr(whatsappOption.Key), + Value: utils.Ptr(whatsappOption.Value), + }) + } + whatsappProviderName := deployment.WhatsappProvider + responseDeployments = append(responseDeployments, openapi.AssistantWhatsappDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + WhatsappProviderName: &whatsappProviderName, + WhatsappOptions: &responseWhatsappOptions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }) + } + totalItem := uint32(totalItems) + currentPage := paginate.GetPage() + c.JSON(http.StatusOK, openapi.GetAllAssistantWhatsappDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &responseDeployments, + Paginated: &openapi.Paginated{ + TotalItem: &totalItem, + CurrentPage: ¤tPage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_assistant_api_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_assistant_api_deployment_rest.go new file mode 100644 index 00000000..bc4d69ab --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_assistant_api_deployment_rest.go @@ -0,0 +1,151 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" +) + +func (deploymentApi *AssistantDeploymentApi) GetAssistantApiDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAssistantApiDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantApiDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantApiDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantApiDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantApiDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAssistantApiDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantApiDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantApiDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantApiDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantApiDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAssistantApiDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantApiDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantApiDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantApiDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantApiDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + deployment, err := deploymentApi.deploymentService.GetAssistantApiDeployment(c, auth, assistantId) + if err != nil { + deploymentApi.logger.Errorf("unable to get assistant api deployment: %v", err) + c.JSON(pkg_errors.GetAssistantApiDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantApiDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantApiDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantApiDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantApiDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + if !validator.NonNil(deployment) { + c.JSON(http.StatusOK, openapi.GetAssistantApiDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: nil, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + + c.JSON(http.StatusOK, openapi.GetAssistantApiDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantApiDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_assistant_debugger_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_assistant_debugger_deployment_rest.go new file mode 100644 index 00000000..8159edf0 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_assistant_debugger_deployment_rest.go @@ -0,0 +1,151 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" +) + +func (deploymentApi *AssistantDeploymentApi) GetAssistantDebuggerDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAssistantDebuggerDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantDebuggerDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAssistantDebuggerDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantDebuggerDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAssistantDebuggerDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantDebuggerDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + deployment, err := deploymentApi.deploymentService.GetAssistantDebuggerDeployment(c, auth, assistantId) + if err != nil { + deploymentApi.logger.Errorf("unable to get assistant debugger deployment: %v", err) + c.JSON(pkg_errors.GetAssistantDebuggerDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantDebuggerDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantDebuggerDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + if !validator.NonNil(deployment) { + c.JSON(http.StatusOK, openapi.GetAssistantDebuggerDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: nil, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + + c.JSON(http.StatusOK, openapi.GetAssistantDebuggerDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantDebuggerDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_assistant_deployment_rest_test.go b/api/assistant-api/api/assistant-deployment/get_assistant_deployment_rest_test.go new file mode 100644 index 00000000..662bc619 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_assistant_deployment_rest_test.go @@ -0,0 +1,265 @@ +package assistant_deployment_api + +import ( + "encoding/json" + "errors" + "net/http" + "net/http/httptest" + "net/url" + "testing" + + "github.com/gin-gonic/gin" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGetAssistantApiDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-api-deployment/123", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAssistantApiDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.getCalled) + assert.Equal(t, uint64(123), service.assistantId) + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, "123", data["assistantId"]) + inputAudio := data["inputAudio"].(map[string]interface{}) + assert.Equal(t, "twilio", inputAudio["audioProvider"]) +} + +func TestGetAssistantDebuggerDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-debugger-deployment/123", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAssistantDebuggerDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.getCalled) + assert.Equal(t, uint64(123), service.assistantId) + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, "123", data["assistantId"]) +} + +func TestGetAssistantPhoneDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-phone-deployment/123", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.getCalled) + assert.Equal(t, uint64(123), service.assistantId) + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, "twilio", data["phoneProviderName"]) +} + +func TestGetAssistantWebpluginDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-webplugin-deployment/123", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAssistantWebpluginDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.getCalled) + assert.Equal(t, uint64(123), service.assistantId) + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, []interface{}{"Book demo", "Talk to support"}, data["suggestion"]) +} + +func TestGetAssistantWhatsappDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-whatsapp-deployment/123", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAssistantWhatsappDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.getCalled) + assert.Equal(t, uint64(123), service.assistantId) + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].(map[string]interface{}) + assert.Equal(t, "gupshup", data["whatsappProviderName"]) +} + +func TestGetAssistantApiDeploymentRest_InvalidAssistantID(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-api-deployment/abc", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "abc"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAssistantApiDeploymentRest(context) + + require.Equal(t, http.StatusBadRequest, recorder.Code) + assert.False(t, service.getCalled) + assert.Contains(t, recorder.Body.String(), pkg_errors.GetAssistantApiDeploymentInvalidAssistantID.Error) +} + +func TestGetAssistantPhoneDeploymentRest_Unauthenticated(t *testing.T) { + gin.SetMode(gin.TestMode) + deploymentApi := newCreateDebuggerDeploymentRestApi(t, &createDebuggerDeploymentRestServiceStub{}) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-phone-deployment/123", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + + deploymentApi.GetAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusUnauthorized, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.GetAssistantPhoneDeploymentUnauthenticated.Error) +} + +func TestGetAssistantWebpluginDeploymentRest_GetDeploymentErrorDoesNotExposeInternalError(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{ + getErr: errors.New("database password leaked"), + } + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-webplugin-deployment/123", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAssistantWebpluginDeploymentRest(context) + + require.Equal(t, http.StatusInternalServerError, recorder.Code) + assert.Contains(t, recorder.Body.String(), pkg_errors.GetAssistantWebpluginDeploymentGetDeployment.Error) + assert.NotContains(t, recorder.Body.String(), "database password leaked") +} + +func TestGetAssistantWhatsappDeploymentRest_NotFoundReturnsSuccessWithNilData(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{ + getNil: true, + } + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest(http.MethodGet, "/v1/assistant-deployment/get-whatsapp-deployment/123", nil) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAssistantWhatsappDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + assert.Nil(t, response["data"]) +} + +func TestGetAllAssistantApiDeploymentRest_HappyPath(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + criterias := url.QueryEscape(`[{"key":"status","logic":"=","value":"ACTIVE"}]`) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodGet, + "/v1/assistant-deployment/get-all-api-deployment/123?page=2&pageSize=10&criterias="+criterias, + nil, + ) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAllAssistantApiDeploymentRest(context) + + require.Equal(t, http.StatusOK, recorder.Code) + assert.True(t, service.getAllCalled) + assert.Equal(t, uint64(123), service.assistantId) + assert.Equal(t, uint32(2), service.page) + assert.Equal(t, uint32(10), service.pageSize) + require.Len(t, service.criterias, 1) + assert.Equal(t, "status", service.criterias[0].GetKey()) + var response map[string]interface{} + require.NoError(t, json.Unmarshal(recorder.Body.Bytes(), &response)) + assert.Equal(t, true, response["success"]) + data := response["data"].([]interface{}) + require.Len(t, data, 1) + paginated := response["paginated"].(map[string]interface{}) + assert.Equal(t, float64(1), paginated["totalItem"]) + assert.Equal(t, float64(2), paginated["currentPage"]) +} + +func TestGetAllAssistantPhoneDeploymentRest_InvalidPage(t *testing.T) { + gin.SetMode(gin.TestMode) + service := &createDebuggerDeploymentRestServiceStub{} + deploymentApi := newCreateDebuggerDeploymentRestApi(t, service) + + recorder := httptest.NewRecorder() + context, _ := gin.CreateTestContext(recorder) + context.Request = httptest.NewRequest( + http.MethodGet, + "/v1/assistant-deployment/get-all-phone-deployment/123?page=abc", + nil, + ) + context.Params = gin.Params{{Key: "assistantId", Value: "123"}} + context.Set(string(types.CTX_), createDebuggerDeploymentRestAuth()) + + deploymentApi.GetAllAssistantPhoneDeploymentRest(context) + + require.Equal(t, http.StatusBadRequest, recorder.Code) + assert.False(t, service.getAllCalled) + assert.Contains(t, recorder.Body.String(), pkg_errors.GetAllAssistantPhoneDeploymentInvalidRequest.Error) +} diff --git a/api/assistant-api/api/assistant-deployment/get_assistant_phone_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_assistant_phone_deployment_rest.go new file mode 100644 index 00000000..cd2396a1 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_assistant_phone_deployment_rest.go @@ -0,0 +1,165 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" +) + +func (deploymentApi *AssistantDeploymentApi) GetAssistantPhoneDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAssistantPhoneDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantPhoneDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAssistantPhoneDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantPhoneDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAssistantPhoneDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantPhoneDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + deployment, err := deploymentApi.deploymentService.GetAssistantPhoneDeployment(c, auth, assistantId) + if err != nil { + deploymentApi.logger.Errorf("unable to get assistant phone deployment: %v", err) + c.JSON(pkg_errors.GetAssistantPhoneDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantPhoneDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantPhoneDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + if !validator.NonNil(deployment) { + c.JSON(http.StatusOK, openapi.GetAssistantPhoneDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: nil, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + + responsePhoneOptions := []openapi.Metadata{} + for _, phoneOption := range deployment.TelephonyOption { + if !validator.NonNil(phoneOption) { + continue + } + responsePhoneOptions = append(responsePhoneOptions, openapi.Metadata{ + Key: utils.Ptr(phoneOption.Key), + Value: utils.Ptr(phoneOption.Value), + }) + } + phoneProviderName := deployment.TelephonyProvider + + c.JSON(http.StatusOK, openapi.GetAssistantPhoneDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantPhoneDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + PhoneProviderName: &phoneProviderName, + PhoneOptions: &responsePhoneOptions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_assistant_webplugin_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_assistant_webplugin_deployment_rest.go new file mode 100644 index 00000000..f10be789 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_assistant_webplugin_deployment_rest.go @@ -0,0 +1,153 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" +) + +func (deploymentApi *AssistantDeploymentApi) GetAssistantWebpluginDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAssistantWebpluginDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantWebpluginDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAssistantWebpluginDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantWebpluginDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAssistantWebpluginDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantWebpluginDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + deployment, err := deploymentApi.deploymentService.GetAssistantWebpluginDeployment(c, auth, assistantId) + if err != nil { + deploymentApi.logger.Errorf("unable to get assistant webplugin deployment: %v", err) + c.JSON(pkg_errors.GetAssistantWebpluginDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantWebpluginDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantWebpluginDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + if !validator.NonNil(deployment) { + c.JSON(http.StatusOK, openapi.GetAssistantWebpluginDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: nil, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + var responseInputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.InputAudio) { + inputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.InputAudio.Id, 10)) + inputAudioStatus := deployment.InputAudio.Status.String() + inputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.InputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + inputAudioOptions = append(inputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseInputAudio = &openapi.DeploymentAudioProvider{ + Id: &inputAudioId, + AudioType: &deployment.InputAudio.AudioType, + AudioProvider: &deployment.InputAudio.AudioProvider, + AudioOptions: &inputAudioOptions, + Status: &inputAudioStatus, + } + } + + var responseOutputAudio *openapi.DeploymentAudioProvider + if validator.NonNil(deployment.OutputAudio) { + outputAudioId := openapi.Uint64String(strconv.FormatUint(deployment.OutputAudio.Id, 10)) + outputAudioStatus := deployment.OutputAudio.Status.String() + outputAudioOptions := []openapi.Metadata{} + for _, audioOption := range deployment.OutputAudio.AudioOptions { + if !validator.NonNil(audioOption) { + continue + } + outputAudioOptions = append(outputAudioOptions, openapi.Metadata{ + Key: utils.Ptr(audioOption.Key), + Value: utils.Ptr(audioOption.Value), + }) + } + responseOutputAudio = &openapi.DeploymentAudioProvider{ + Id: &outputAudioId, + AudioType: &deployment.OutputAudio.AudioType, + AudioProvider: &deployment.OutputAudio.AudioProvider, + AudioOptions: &outputAudioOptions, + Status: &outputAudioStatus, + } + } + responseSuggestions := []string(deployment.Suggestion) + + c.JSON(http.StatusOK, openapi.GetAssistantWebpluginDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantWebpluginDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + InputAudio: responseInputAudio, + OutputAudio: responseOutputAudio, + Suggestion: &responseSuggestions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/api/assistant-deployment/get_assistant_whatsapp_deployment_rest.go b/api/assistant-api/api/assistant-deployment/get_assistant_whatsapp_deployment_rest.go new file mode 100644 index 00000000..31ebea25 --- /dev/null +++ b/api/assistant-api/api/assistant-deployment/get_assistant_whatsapp_deployment_rest.go @@ -0,0 +1,117 @@ +// Copyright (c) 2023-2025 RapidaAI +// Author: Prashant Srivastav +// +// Licensed under GPL-2.0 with Rapida Additional Terms. +// See LICENSE.md or contact sales@rapida.ai for commercial usage. +package assistant_deployment_api + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/rapidaai/openapi" + pkg_errors "github.com/rapidaai/pkg/errors" + "github.com/rapidaai/pkg/types" + "github.com/rapidaai/pkg/utils" + "github.com/rapidaai/pkg/validator" +) + +func (deploymentApi *AssistantDeploymentApi) GetAssistantWhatsappDeploymentRest(c *gin.Context) { + auth, isAuthenticated := types.GetAuthPrinciple(c) + if !isAuthenticated { + c.JSON(pkg_errors.GetAssistantWhatsappDeploymentUnauthenticated.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentUnauthenticated.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantWhatsappDeploymentUnauthenticated.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentUnauthenticated.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentUnauthenticated.ErrorMessage), + }, + }) + return + } + if !auth.HasUser() || !auth.HasProject() || !auth.HasOrganization() { + c.JSON(pkg_errors.GetAssistantWhatsappDeploymentMissingAuthScope.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentMissingAuthScope.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantWhatsappDeploymentMissingAuthScope.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentMissingAuthScope.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentMissingAuthScope.ErrorMessage), + }, + }) + return + } + + assistantId, err := strconv.ParseUint(c.Param("assistantId"), 10, 64) + if err != nil || assistantId == 0 { + c.JSON(pkg_errors.GetAssistantWhatsappDeploymentInvalidAssistantID.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentInvalidAssistantID.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantWhatsappDeploymentInvalidAssistantID.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentInvalidAssistantID.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentInvalidAssistantID.ErrorMessage), + }, + }) + return + } + + deployment, err := deploymentApi.deploymentService.GetAssistantWhatsappDeployment(c, auth, assistantId) + if err != nil { + deploymentApi.logger.Errorf("unable to get assistant whatsapp deployment: %v", err) + c.JSON(pkg_errors.GetAssistantWhatsappDeploymentGetDeployment.HTTPStatusCode, openapi.ErrorResponse{ + Code: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentGetDeployment.HTTPStatusCodeInt32()), + Success: utils.Ptr(false), + Error: &openapi.Error{ + ErrorCode: utils.Ptr(openapi.Uint64String(pkg_errors.GetAssistantWhatsappDeploymentGetDeployment.CodeString())), + ErrorMessage: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentGetDeployment.Error), + HumanMessage: utils.Ptr(pkg_errors.GetAssistantWhatsappDeploymentGetDeployment.ErrorMessage), + }, + }) + return + } + if !validator.NonNil(deployment) { + c.JSON(http.StatusOK, openapi.GetAssistantWhatsappDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: nil, + }) + return + } + + deploymentId := openapi.Uint64String(strconv.FormatUint(deployment.Id, 10)) + deploymentAssistantId := openapi.Uint64String(strconv.FormatUint(deployment.AssistantId, 10)) + deploymentStatus := deployment.Status.String() + + responseWhatsappOptions := []openapi.Metadata{} + for _, whatsappOption := range deployment.WhatsappOptions { + if !validator.NonNil(whatsappOption) { + continue + } + responseWhatsappOptions = append(responseWhatsappOptions, openapi.Metadata{ + Key: utils.Ptr(whatsappOption.Key), + Value: utils.Ptr(whatsappOption.Value), + }) + } + whatsappProviderName := deployment.WhatsappProvider + + c.JSON(http.StatusOK, openapi.GetAssistantWhatsappDeploymentResponse{ + Code: utils.Ptr(int32(http.StatusOK)), + Success: utils.Ptr(true), + Data: &openapi.AssistantWhatsappDeployment{ + Id: &deploymentId, + AssistantId: &deploymentAssistantId, + Greeting: deployment.Greeting, + Mistake: deployment.Mistake, + WhatsappProviderName: &whatsappProviderName, + WhatsappOptions: &responseWhatsappOptions, + Status: &deploymentStatus, + MaxSessionDuration: deployment.MaxSessionDuration, + IdealTimeout: deployment.IdleTimeout, + IdealTimeoutBackoff: deployment.IdleTimeoutBackoff, + IdealTimeoutMessage: deployment.IdleTimeoutMessage, + }, + }) +} diff --git a/api/assistant-api/router/assistant.go b/api/assistant-api/router/assistant.go index 1c4d2896..f5de1dcd 100644 --- a/api/assistant-api/router/assistant.go +++ b/api/assistant-api/router/assistant.go @@ -63,7 +63,21 @@ func AssistantDeploymentApiRoute(Cfg *config.AssistantConfig, apiv1 := engine.Group("v1/assistant-deployment") deploymentApi := assistantDeploymentApi.NewAssistantDeploymentApi(Cfg, Logger, Postgres) + apiv1.POST("/create-api-deployment", deploymentApi.CreateAssistantApiDeploymentRest) apiv1.POST("/create-debugger-deployment", deploymentApi.CreateAssistantDebuggerDeploymentRest) + apiv1.POST("/create-phone-deployment", deploymentApi.CreateAssistantPhoneDeploymentRest) + apiv1.POST("/create-webplugin-deployment", deploymentApi.CreateAssistantWebpluginDeploymentRest) + apiv1.POST("/create-whatsapp-deployment", deploymentApi.CreateAssistantWhatsappDeploymentRest) + apiv1.GET("/get-api-deployment/:assistantId", deploymentApi.GetAssistantApiDeploymentRest) + apiv1.GET("/get-debugger-deployment/:assistantId", deploymentApi.GetAssistantDebuggerDeploymentRest) + apiv1.GET("/get-phone-deployment/:assistantId", deploymentApi.GetAssistantPhoneDeploymentRest) + apiv1.GET("/get-webplugin-deployment/:assistantId", deploymentApi.GetAssistantWebpluginDeploymentRest) + apiv1.GET("/get-whatsapp-deployment/:assistantId", deploymentApi.GetAssistantWhatsappDeploymentRest) + apiv1.GET("/get-all-api-deployment/:assistantId", deploymentApi.GetAllAssistantApiDeploymentRest) + apiv1.GET("/get-all-debugger-deployment/:assistantId", deploymentApi.GetAllAssistantDebuggerDeploymentRest) + apiv1.GET("/get-all-phone-deployment/:assistantId", deploymentApi.GetAllAssistantPhoneDeploymentRest) + apiv1.GET("/get-all-webplugin-deployment/:assistantId", deploymentApi.GetAllAssistantWebpluginDeploymentRest) + apiv1.GET("/get-all-whatsapp-deployment/:assistantId", deploymentApi.GetAllAssistantWhatsappDeploymentRest) } func AssistantConversationApiRoute( diff --git a/openapi/artifacts/assistant-api.yaml b/openapi/artifacts/assistant-api.yaml index 4c58dd07..cf6ed6ce 100644 --- a/openapi/artifacts/assistant-api.yaml +++ b/openapi/artifacts/assistant-api.yaml @@ -80,6 +80,694 @@ paths: application/json: schema: $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/create-phone-deployment: + post: + operationId: createAssistantPhoneDeployment + summary: Create assistant phone deployment + description: Creates a phone deployment for an assistant. This endpoint requires user authentication with organization and project scope. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateAssistantPhoneDeploymentRequest" + responses: + "200": + description: Assistant phone deployment created + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantPhoneDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to create assistant phone deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/create-api-deployment: + post: + operationId: createAssistantApiDeployment + summary: Create assistant API deployment + description: Creates an API deployment for an assistant. This endpoint requires user authentication with organization and project scope. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateAssistantApiDeploymentRequest" + responses: + "200": + description: Assistant API deployment created + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantApiDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to create assistant API deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/create-webplugin-deployment: + post: + operationId: createAssistantWebpluginDeployment + summary: Create assistant webplugin deployment + description: Creates a webplugin deployment for an assistant. This endpoint requires user authentication with organization and project scope. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateAssistantWebpluginDeploymentRequest" + responses: + "200": + description: Assistant webplugin deployment created + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantWebpluginDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to create assistant webplugin deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/create-whatsapp-deployment: + post: + operationId: createAssistantWhatsappDeployment + summary: Create assistant WhatsApp deployment + description: Creates a WhatsApp deployment for an assistant. This endpoint requires user authentication with organization and project scope. + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateAssistantWhatsappDeploymentRequest" + responses: + "200": + description: Assistant WhatsApp deployment created + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantWhatsappDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to create assistant WhatsApp deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-api-deployment/{assistantId}: + get: + operationId: getAssistantApiDeployment + summary: Get assistant API deployment + description: Gets the latest API deployment for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + responses: + "200": + description: Assistant API deployment + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantApiDeploymentResponse" + "400": + description: Invalid assistantId + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant API deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-debugger-deployment/{assistantId}: + get: + operationId: getAssistantDebuggerDeployment + summary: Get assistant debugger deployment + description: Gets the latest debugger deployment for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + responses: + "200": + description: Assistant debugger deployment + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantDebuggerDeploymentResponse" + "400": + description: Invalid assistantId + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant debugger deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-phone-deployment/{assistantId}: + get: + operationId: getAssistantPhoneDeployment + summary: Get assistant phone deployment + description: Gets the latest phone deployment for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + responses: + "200": + description: Assistant phone deployment + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantPhoneDeploymentResponse" + "400": + description: Invalid assistantId + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant phone deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-webplugin-deployment/{assistantId}: + get: + operationId: getAssistantWebpluginDeployment + summary: Get assistant webplugin deployment + description: Gets the latest webplugin deployment for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + responses: + "200": + description: Assistant webplugin deployment + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantWebpluginDeploymentResponse" + "400": + description: Invalid assistantId + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant webplugin deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-whatsapp-deployment/{assistantId}: + get: + operationId: getAssistantWhatsappDeployment + summary: Get assistant WhatsApp deployment + description: Gets the latest WhatsApp deployment for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + responses: + "200": + description: Assistant WhatsApp deployment + content: + application/json: + schema: + $ref: "#/components/schemas/GetAssistantWhatsappDeploymentResponse" + "400": + description: Invalid assistantId + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant WhatsApp deployment + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-all-api-deployment/{assistantId}: + get: + operationId: getAllAssistantApiDeployment + summary: Get all assistant API deployments + description: Gets API deployments for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + - name: page + in: query + required: false + schema: + type: integer + format: uint32 + default: 1 + - name: pageSize + in: query + required: false + schema: + type: integer + format: uint32 + default: 20 + - name: criterias + in: query + required: false + description: JSON encoded array of Criteria objects. + schema: + type: string + responses: + "200": + description: Assistant API deployments + content: + application/json: + schema: + $ref: "#/components/schemas/GetAllAssistantApiDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant API deployments + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-all-debugger-deployment/{assistantId}: + get: + operationId: getAllAssistantDebuggerDeployment + summary: Get all assistant debugger deployments + description: Gets debugger deployments for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + - name: page + in: query + required: false + schema: + type: integer + format: uint32 + default: 1 + - name: pageSize + in: query + required: false + schema: + type: integer + format: uint32 + default: 20 + - name: criterias + in: query + required: false + description: JSON encoded array of Criteria objects. + schema: + type: string + responses: + "200": + description: Assistant debugger deployments + content: + application/json: + schema: + $ref: "#/components/schemas/GetAllAssistantDebuggerDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant debugger deployments + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-all-phone-deployment/{assistantId}: + get: + operationId: getAllAssistantPhoneDeployment + summary: Get all assistant phone deployments + description: Gets phone deployments for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + - name: page + in: query + required: false + schema: + type: integer + format: uint32 + default: 1 + - name: pageSize + in: query + required: false + schema: + type: integer + format: uint32 + default: 20 + - name: criterias + in: query + required: false + description: JSON encoded array of Criteria objects. + schema: + type: string + responses: + "200": + description: Assistant phone deployments + content: + application/json: + schema: + $ref: "#/components/schemas/GetAllAssistantPhoneDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant phone deployments + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-all-webplugin-deployment/{assistantId}: + get: + operationId: getAllAssistantWebpluginDeployment + summary: Get all assistant webplugin deployments + description: Gets webplugin deployments for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + - name: page + in: query + required: false + schema: + type: integer + format: uint32 + default: 1 + - name: pageSize + in: query + required: false + schema: + type: integer + format: uint32 + default: 20 + - name: criterias + in: query + required: false + description: JSON encoded array of Criteria objects. + schema: + type: string + responses: + "200": + description: Assistant webplugin deployments + content: + application/json: + schema: + $ref: "#/components/schemas/GetAllAssistantWebpluginDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant webplugin deployments + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + /v1/assistant-deployment/get-all-whatsapp-deployment/{assistantId}: + get: + operationId: getAllAssistantWhatsappDeployment + summary: Get all assistant WhatsApp deployments + description: Gets WhatsApp deployments for an assistant. This endpoint requires user authentication with organization and project scope. + parameters: + - name: assistantId + in: path + required: true + schema: + $ref: "./common.yaml#/components/schemas/Uint64String" + - name: page + in: query + required: false + schema: + type: integer + format: uint32 + default: 1 + - name: pageSize + in: query + required: false + schema: + type: integer + format: uint32 + default: 20 + - name: criterias + in: query + required: false + description: JSON encoded array of Criteria objects. + schema: + type: string + responses: + "200": + description: Assistant WhatsApp deployments + content: + application/json: + schema: + $ref: "#/components/schemas/GetAllAssistantWhatsappDeploymentResponse" + "400": + description: Invalid request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "401": + description: Unauthenticated request + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "403": + description: Missing authentication scope + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" + "500": + description: Failed to get assistant WhatsApp deployments + content: + application/json: + schema: + $ref: "./common.yaml#/components/schemas/ErrorResponse" components: schemas: CreateAssistantRequest: @@ -112,12 +800,152 @@ components: type: array items: type: string - name: - type: string - CreateAssistantDebuggerDeploymentRequest: + name: + type: string + CreateAssistantDebuggerDeploymentRequest: + type: object + required: + - assistantId + properties: + assistantId: + $ref: "./common.yaml#/components/schemas/Uint64String" + greeting: + type: string + mistake: + type: string + idealTimeout: + type: integer + format: uint64 + minimum: 15 + maximum: 120 + idealTimeoutBackoff: + type: integer + format: uint64 + minimum: 0 + maximum: 5 + idealTimeoutMessage: + type: string + maxSessionDuration: + type: integer + format: uint64 + minimum: 180 + maximum: 600 + inputAudio: + $ref: "#/components/schemas/DeploymentAudioProviderRequest" + outputAudio: + $ref: "#/components/schemas/DeploymentAudioProviderRequest" + CreateAssistantPhoneDeploymentRequest: + type: object + required: + - assistantId + - phoneProviderName + properties: + assistantId: + $ref: "./common.yaml#/components/schemas/Uint64String" + greeting: + type: string + mistake: + type: string + idealTimeout: + type: integer + format: uint64 + minimum: 15 + maximum: 120 + idealTimeoutBackoff: + type: integer + format: uint64 + minimum: 0 + maximum: 5 + idealTimeoutMessage: + type: string + maxSessionDuration: + type: integer + format: uint64 + minimum: 180 + maximum: 600 + phoneProviderName: + type: string + phoneOptions: + type: array + items: + $ref: "./common.yaml#/components/schemas/Metadata" + inputAudio: + $ref: "#/components/schemas/DeploymentAudioProviderRequest" + outputAudio: + $ref: "#/components/schemas/DeploymentAudioProviderRequest" + CreateAssistantApiDeploymentRequest: + type: object + required: + - assistantId + properties: + assistantId: + $ref: "./common.yaml#/components/schemas/Uint64String" + greeting: + type: string + mistake: + type: string + idealTimeout: + type: integer + format: uint64 + minimum: 15 + maximum: 120 + idealTimeoutBackoff: + type: integer + format: uint64 + minimum: 0 + maximum: 5 + idealTimeoutMessage: + type: string + maxSessionDuration: + type: integer + format: uint64 + minimum: 180 + maximum: 600 + inputAudio: + $ref: "#/components/schemas/DeploymentAudioProviderRequest" + outputAudio: + $ref: "#/components/schemas/DeploymentAudioProviderRequest" + CreateAssistantWebpluginDeploymentRequest: + type: object + required: + - assistantId + properties: + assistantId: + $ref: "./common.yaml#/components/schemas/Uint64String" + greeting: + type: string + mistake: + type: string + idealTimeout: + type: integer + format: uint64 + minimum: 15 + maximum: 120 + idealTimeoutBackoff: + type: integer + format: uint64 + minimum: 0 + maximum: 5 + idealTimeoutMessage: + type: string + maxSessionDuration: + type: integer + format: uint64 + minimum: 180 + maximum: 600 + suggestion: + type: array + items: + type: string + inputAudio: + $ref: "#/components/schemas/DeploymentAudioProviderRequest" + outputAudio: + $ref: "#/components/schemas/DeploymentAudioProviderRequest" + CreateAssistantWhatsappDeploymentRequest: type: object required: - assistantId + - whatsappProviderName properties: assistantId: $ref: "./common.yaml#/components/schemas/Uint64String" @@ -142,10 +970,12 @@ components: format: uint64 minimum: 180 maximum: 600 - inputAudio: - $ref: "#/components/schemas/DeploymentAudioProviderRequest" - outputAudio: - $ref: "#/components/schemas/DeploymentAudioProviderRequest" + whatsappProviderName: + type: string + whatsappOptions: + type: array + items: + $ref: "./common.yaml#/components/schemas/Metadata" DeploymentAudioProviderRequest: type: object required: @@ -311,6 +1141,134 @@ components: $ref: "#/components/schemas/AssistantDebuggerDeployment" error: $ref: "./common.yaml#/components/schemas/Error" + GetAssistantPhoneDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + $ref: "#/components/schemas/AssistantPhoneDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + GetAssistantApiDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + $ref: "#/components/schemas/AssistantApiDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + GetAssistantWebpluginDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + $ref: "#/components/schemas/AssistantWebpluginDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + GetAssistantWhatsappDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + $ref: "#/components/schemas/AssistantWhatsappDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + GetAllAssistantApiDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + type: array + items: + $ref: "#/components/schemas/AssistantApiDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + paginated: + $ref: "./common.yaml#/components/schemas/Paginated" + GetAllAssistantDebuggerDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + type: array + items: + $ref: "#/components/schemas/AssistantDebuggerDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + paginated: + $ref: "./common.yaml#/components/schemas/Paginated" + GetAllAssistantPhoneDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + type: array + items: + $ref: "#/components/schemas/AssistantPhoneDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + paginated: + $ref: "./common.yaml#/components/schemas/Paginated" + GetAllAssistantWebpluginDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + type: array + items: + $ref: "#/components/schemas/AssistantWebpluginDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + paginated: + $ref: "./common.yaml#/components/schemas/Paginated" + GetAllAssistantWhatsappDeploymentResponse: + type: object + properties: + code: + type: integer + format: int32 + success: + type: boolean + data: + type: array + items: + $ref: "#/components/schemas/AssistantWhatsappDeployment" + error: + $ref: "./common.yaml#/components/schemas/Error" + paginated: + $ref: "./common.yaml#/components/schemas/Paginated" AssistantDebuggerDeployment: type: object properties: @@ -345,6 +1303,154 @@ components: maximum: 5 idealTimeoutMessage: type: string + AssistantPhoneDeployment: + type: object + properties: + id: + $ref: "./common.yaml#/components/schemas/Uint64String" + assistantId: + $ref: "./common.yaml#/components/schemas/Uint64String" + greeting: + type: string + mistake: + type: string + inputAudio: + $ref: "#/components/schemas/DeploymentAudioProvider" + outputAudio: + $ref: "#/components/schemas/DeploymentAudioProvider" + phoneProviderName: + type: string + phoneOptions: + type: array + items: + $ref: "./common.yaml#/components/schemas/Metadata" + status: + type: string + maxSessionDuration: + type: integer + format: uint64 + minimum: 180 + maximum: 600 + idealTimeout: + type: integer + format: uint64 + minimum: 15 + maximum: 120 + idealTimeoutBackoff: + type: integer + format: uint64 + minimum: 0 + maximum: 5 + idealTimeoutMessage: + type: string + AssistantApiDeployment: + type: object + properties: + id: + $ref: "./common.yaml#/components/schemas/Uint64String" + assistantId: + $ref: "./common.yaml#/components/schemas/Uint64String" + greeting: + type: string + mistake: + type: string + inputAudio: + $ref: "#/components/schemas/DeploymentAudioProvider" + outputAudio: + $ref: "#/components/schemas/DeploymentAudioProvider" + status: + type: string + maxSessionDuration: + type: integer + format: uint64 + minimum: 180 + maximum: 600 + idealTimeout: + type: integer + format: uint64 + minimum: 15 + maximum: 120 + idealTimeoutBackoff: + type: integer + format: uint64 + minimum: 0 + maximum: 5 + idealTimeoutMessage: + type: string + AssistantWebpluginDeployment: + type: object + properties: + id: + $ref: "./common.yaml#/components/schemas/Uint64String" + assistantId: + $ref: "./common.yaml#/components/schemas/Uint64String" + greeting: + type: string + mistake: + type: string + inputAudio: + $ref: "#/components/schemas/DeploymentAudioProvider" + outputAudio: + $ref: "#/components/schemas/DeploymentAudioProvider" + suggestion: + type: array + items: + type: string + status: + type: string + maxSessionDuration: + type: integer + format: uint64 + minimum: 180 + maximum: 600 + idealTimeout: + type: integer + format: uint64 + minimum: 15 + maximum: 120 + idealTimeoutBackoff: + type: integer + format: uint64 + minimum: 0 + maximum: 5 + idealTimeoutMessage: + type: string + AssistantWhatsappDeployment: + type: object + properties: + id: + $ref: "./common.yaml#/components/schemas/Uint64String" + assistantId: + $ref: "./common.yaml#/components/schemas/Uint64String" + greeting: + type: string + mistake: + type: string + whatsappProviderName: + type: string + whatsappOptions: + type: array + items: + $ref: "./common.yaml#/components/schemas/Metadata" + status: + type: string + maxSessionDuration: + type: integer + format: uint64 + minimum: 180 + maximum: 600 + idealTimeout: + type: integer + format: uint64 + minimum: 15 + maximum: 120 + idealTimeoutBackoff: + type: integer + format: uint64 + minimum: 0 + maximum: 5 + idealTimeoutMessage: + type: string DeploymentAudioProvider: type: object properties: diff --git a/openapi/artifacts/common.yaml b/openapi/artifacts/common.yaml index 401e7b2b..76ff67f9 100644 --- a/openapi/artifacts/common.yaml +++ b/openapi/artifacts/common.yaml @@ -70,6 +70,116 @@ components: - `1004007`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. - `1004008`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. - `1004009`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. + + Create Assistant Phone Deployment: + - `1005001`: invalid request - Invalid request. + - `1005002`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1005003`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1005004`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1005005`: unable to create assistant phone deployment - Unable to create assistant phone deployment, please try again later. + - `1005006`: invalid audio provider parameter - Please provide a valid audioProvider parameter. + - `1005007`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. + - `1005008`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. + - `1005009`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. + - `1005010`: missing phone_provider_name parameter - Please provide the required phoneProviderName parameter. + + Create Assistant API Deployment: + - `1006001`: invalid request - Invalid request. + - `1006002`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1006003`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1006004`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1006005`: unable to create assistant api deployment - Unable to create assistant api deployment, please try again later. + - `1006006`: invalid audio provider parameter - Please provide a valid audioProvider parameter. + - `1006007`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. + - `1006008`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. + - `1006009`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. + + Create Assistant Webplugin Deployment: + - `1007001`: invalid request - Invalid request. + - `1007002`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1007003`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1007004`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1007005`: unable to create assistant webplugin deployment - Unable to create assistant webplugin deployment, please try again later. + - `1007006`: invalid audio provider parameter - Please provide a valid audioProvider parameter. + - `1007007`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. + - `1007008`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. + - `1007009`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. + + Create Assistant WhatsApp Deployment: + - `1008001`: invalid request - Invalid request. + - `1008002`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1008003`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1008004`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1008005`: unable to create assistant whatsapp deployment - Unable to create assistant whatsapp deployment, please try again later. + - `1008006`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. + - `1008007`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. + - `1008008`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. + - `1008009`: missing whatsapp_provider_name parameter - Please provide the required whatsappProviderName parameter. + + Get Assistant Debugger Deployment: + - `1009001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1009002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1009003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1009004`: unable to get assistant debugger deployment - Unable to get assistant debugger deployment, please try again later. + + Get Assistant Phone Deployment: + - `1010001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1010002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1010003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1010004`: unable to get assistant phone deployment - Unable to get assistant phone deployment, please try again later. + + Get Assistant API Deployment: + - `1011001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1011002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1011003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1011004`: unable to get assistant api deployment - Unable to get assistant api deployment, please try again later. + + Get Assistant Webplugin Deployment: + - `1012001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1012002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1012003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1012004`: unable to get assistant webplugin deployment - Unable to get assistant webplugin deployment, please try again later. + + Get Assistant WhatsApp Deployment: + - `1013001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1013002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1013003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1013004`: unable to get assistant whatsapp deployment - Unable to get assistant whatsapp deployment, please try again later. + + Get All Assistant Debugger Deployment: + - `1014001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1014002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1014003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1014004`: invalid request - Invalid request. + - `1014005`: unable to get assistant debugger deployments - Unable to get assistant debugger deployments, please try again later. + + Get All Assistant Phone Deployment: + - `1015001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1015002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1015003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1015004`: invalid request - Invalid request. + - `1015005`: unable to get assistant phone deployments - Unable to get assistant phone deployments, please try again later. + + Get All Assistant API Deployment: + - `1016001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1016002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1016003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1016004`: invalid request - Invalid request. + - `1016005`: unable to get assistant api deployments - Unable to get assistant api deployments, please try again later. + + Get All Assistant Webplugin Deployment: + - `1017001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1017002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1017003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1017004`: invalid request - Invalid request. + - `1017005`: unable to get assistant webplugin deployments - Unable to get assistant webplugin deployments, please try again later. + + Get All Assistant WhatsApp Deployment: + - `1018001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. + - `1018002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. + - `1018003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. + - `1018004`: invalid request - Invalid request. + - `1018005`: unable to get assistant whatsapp deployments - Unable to get assistant whatsapp deployments, please try again later. AssistantDefinition: type: object properties: @@ -136,6 +246,33 @@ components: type: string value: type: string + Criteria: + type: object + properties: + key: + type: string + value: + type: string + logic: + type: string + Paginate: + type: object + properties: + page: + type: integer + format: uint32 + pageSize: + type: integer + format: uint32 + Paginated: + type: object + properties: + currentPage: + type: integer + format: uint32 + totalItem: + type: integer + format: uint32 Argument: type: object properties: diff --git a/openapi/assistant.gen.go b/openapi/assistant.gen.go index 2a0a13d2..0b8de840 100644 --- a/openapi/assistant.gen.go +++ b/openapi/assistant.gen.go @@ -32,6 +32,21 @@ type Assistant struct { Visibility *string `json:"visibility,omitempty"` } +// AssistantApiDeployment defines model for AssistantApiDeployment. +type AssistantApiDeployment struct { + AssistantId *Uint64String `json:"assistantId,omitempty"` + Greeting *string `json:"greeting,omitempty"` + Id *Uint64String `json:"id,omitempty"` + IdealTimeout *uint64 `json:"idealTimeout,omitempty"` + IdealTimeoutBackoff *uint64 `json:"idealTimeoutBackoff,omitempty"` + IdealTimeoutMessage *string `json:"idealTimeoutMessage,omitempty"` + InputAudio *DeploymentAudioProvider `json:"inputAudio,omitempty"` + MaxSessionDuration *uint64 `json:"maxSessionDuration,omitempty"` + Mistake *string `json:"mistake,omitempty"` + OutputAudio *DeploymentAudioProvider `json:"outputAudio,omitempty"` + Status *string `json:"status,omitempty"` +} + // AssistantDebuggerDeployment defines model for AssistantDebuggerDeployment. type AssistantDebuggerDeployment struct { AssistantId *Uint64String `json:"assistantId,omitempty"` @@ -61,6 +76,23 @@ type AssistantKnowledge struct { TopK *uint32 `json:"topK,omitempty"` } +// AssistantPhoneDeployment defines model for AssistantPhoneDeployment. +type AssistantPhoneDeployment struct { + AssistantId *Uint64String `json:"assistantId,omitempty"` + Greeting *string `json:"greeting,omitempty"` + Id *Uint64String `json:"id,omitempty"` + IdealTimeout *uint64 `json:"idealTimeout,omitempty"` + IdealTimeoutBackoff *uint64 `json:"idealTimeoutBackoff,omitempty"` + IdealTimeoutMessage *string `json:"idealTimeoutMessage,omitempty"` + InputAudio *DeploymentAudioProvider `json:"inputAudio,omitempty"` + MaxSessionDuration *uint64 `json:"maxSessionDuration,omitempty"` + Mistake *string `json:"mistake,omitempty"` + OutputAudio *DeploymentAudioProvider `json:"outputAudio,omitempty"` + PhoneOptions *[]Metadata `json:"phoneOptions,omitempty"` + PhoneProviderName *string `json:"phoneProviderName,omitempty"` + Status *string `json:"status,omitempty"` +} + // AssistantProviderAgentkit defines model for AssistantProviderAgentkit. type AssistantProviderAgentkit struct { AssistantId *Uint64String `json:"assistantId,omitempty"` @@ -113,6 +145,50 @@ type AssistantTool struct { Status *string `json:"status,omitempty"` } +// AssistantWebpluginDeployment defines model for AssistantWebpluginDeployment. +type AssistantWebpluginDeployment struct { + AssistantId *Uint64String `json:"assistantId,omitempty"` + Greeting *string `json:"greeting,omitempty"` + Id *Uint64String `json:"id,omitempty"` + IdealTimeout *uint64 `json:"idealTimeout,omitempty"` + IdealTimeoutBackoff *uint64 `json:"idealTimeoutBackoff,omitempty"` + IdealTimeoutMessage *string `json:"idealTimeoutMessage,omitempty"` + InputAudio *DeploymentAudioProvider `json:"inputAudio,omitempty"` + MaxSessionDuration *uint64 `json:"maxSessionDuration,omitempty"` + Mistake *string `json:"mistake,omitempty"` + OutputAudio *DeploymentAudioProvider `json:"outputAudio,omitempty"` + Status *string `json:"status,omitempty"` + Suggestion *[]string `json:"suggestion,omitempty"` +} + +// AssistantWhatsappDeployment defines model for AssistantWhatsappDeployment. +type AssistantWhatsappDeployment struct { + AssistantId *Uint64String `json:"assistantId,omitempty"` + Greeting *string `json:"greeting,omitempty"` + Id *Uint64String `json:"id,omitempty"` + IdealTimeout *uint64 `json:"idealTimeout,omitempty"` + IdealTimeoutBackoff *uint64 `json:"idealTimeoutBackoff,omitempty"` + IdealTimeoutMessage *string `json:"idealTimeoutMessage,omitempty"` + MaxSessionDuration *uint64 `json:"maxSessionDuration,omitempty"` + Mistake *string `json:"mistake,omitempty"` + Status *string `json:"status,omitempty"` + WhatsappOptions *[]Metadata `json:"whatsappOptions,omitempty"` + WhatsappProviderName *string `json:"whatsappProviderName,omitempty"` +} + +// CreateAssistantApiDeploymentRequest defines model for CreateAssistantApiDeploymentRequest. +type CreateAssistantApiDeploymentRequest struct { + AssistantId Uint64String `json:"assistantId"` + Greeting *string `json:"greeting,omitempty"` + IdealTimeout *uint64 `json:"idealTimeout,omitempty"` + IdealTimeoutBackoff *uint64 `json:"idealTimeoutBackoff,omitempty"` + IdealTimeoutMessage *string `json:"idealTimeoutMessage,omitempty"` + InputAudio *DeploymentAudioProviderRequest `json:"inputAudio,omitempty"` + MaxSessionDuration *uint64 `json:"maxSessionDuration,omitempty"` + Mistake *string `json:"mistake,omitempty"` + OutputAudio *DeploymentAudioProviderRequest `json:"outputAudio,omitempty"` +} + // CreateAssistantDebuggerDeploymentRequest defines model for CreateAssistantDebuggerDeploymentRequest. type CreateAssistantDebuggerDeploymentRequest struct { AssistantId Uint64String `json:"assistantId"` @@ -139,6 +215,21 @@ type CreateAssistantKnowledgeRequest struct { TopK *uint32 `json:"topK,omitempty"` } +// CreateAssistantPhoneDeploymentRequest defines model for CreateAssistantPhoneDeploymentRequest. +type CreateAssistantPhoneDeploymentRequest struct { + AssistantId Uint64String `json:"assistantId"` + Greeting *string `json:"greeting,omitempty"` + IdealTimeout *uint64 `json:"idealTimeout,omitempty"` + IdealTimeoutBackoff *uint64 `json:"idealTimeoutBackoff,omitempty"` + IdealTimeoutMessage *string `json:"idealTimeoutMessage,omitempty"` + InputAudio *DeploymentAudioProviderRequest `json:"inputAudio,omitempty"` + MaxSessionDuration *uint64 `json:"maxSessionDuration,omitempty"` + Mistake *string `json:"mistake,omitempty"` + OutputAudio *DeploymentAudioProviderRequest `json:"outputAudio,omitempty"` + PhoneOptions *[]Metadata `json:"phoneOptions,omitempty"` + PhoneProviderName string `json:"phoneProviderName"` +} + // CreateAssistantProviderAgentkit defines model for CreateAssistantProviderAgentkit. type CreateAssistantProviderAgentkit struct { AgentKitUrl string `json:"agentKitUrl"` @@ -193,6 +284,33 @@ type CreateAssistantToolRequest struct { Name *string `json:"name,omitempty"` } +// CreateAssistantWebpluginDeploymentRequest defines model for CreateAssistantWebpluginDeploymentRequest. +type CreateAssistantWebpluginDeploymentRequest struct { + AssistantId Uint64String `json:"assistantId"` + Greeting *string `json:"greeting,omitempty"` + IdealTimeout *uint64 `json:"idealTimeout,omitempty"` + IdealTimeoutBackoff *uint64 `json:"idealTimeoutBackoff,omitempty"` + IdealTimeoutMessage *string `json:"idealTimeoutMessage,omitempty"` + InputAudio *DeploymentAudioProviderRequest `json:"inputAudio,omitempty"` + MaxSessionDuration *uint64 `json:"maxSessionDuration,omitempty"` + Mistake *string `json:"mistake,omitempty"` + OutputAudio *DeploymentAudioProviderRequest `json:"outputAudio,omitempty"` + Suggestion *[]string `json:"suggestion,omitempty"` +} + +// CreateAssistantWhatsappDeploymentRequest defines model for CreateAssistantWhatsappDeploymentRequest. +type CreateAssistantWhatsappDeploymentRequest struct { + AssistantId Uint64String `json:"assistantId"` + Greeting *string `json:"greeting,omitempty"` + IdealTimeout *uint64 `json:"idealTimeout,omitempty"` + IdealTimeoutBackoff *uint64 `json:"idealTimeoutBackoff,omitempty"` + IdealTimeoutMessage *string `json:"idealTimeoutMessage,omitempty"` + MaxSessionDuration *uint64 `json:"maxSessionDuration,omitempty"` + Mistake *string `json:"mistake,omitempty"` + WhatsappOptions *[]Metadata `json:"whatsappOptions,omitempty"` + WhatsappProviderName string `json:"whatsappProviderName"` +} + // DeploymentAudioProvider defines model for DeploymentAudioProvider. type DeploymentAudioProvider struct { AudioOptions *[]Metadata `json:"audioOptions,omitempty"` @@ -210,6 +328,77 @@ type DeploymentAudioProviderRequest struct { Status *string `json:"status,omitempty"` } +// GetAllAssistantApiDeploymentResponse defines model for GetAllAssistantApiDeploymentResponse. +type GetAllAssistantApiDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *[]AssistantApiDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Paginated *Paginated `json:"paginated,omitempty"` + Success *bool `json:"success,omitempty"` +} + +// GetAllAssistantDebuggerDeploymentResponse defines model for GetAllAssistantDebuggerDeploymentResponse. +type GetAllAssistantDebuggerDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *[]AssistantDebuggerDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Paginated *Paginated `json:"paginated,omitempty"` + Success *bool `json:"success,omitempty"` +} + +// GetAllAssistantPhoneDeploymentResponse defines model for GetAllAssistantPhoneDeploymentResponse. +type GetAllAssistantPhoneDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *[]AssistantPhoneDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Paginated *Paginated `json:"paginated,omitempty"` + Success *bool `json:"success,omitempty"` +} + +// GetAllAssistantWebpluginDeploymentResponse defines model for GetAllAssistantWebpluginDeploymentResponse. +type GetAllAssistantWebpluginDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *[]AssistantWebpluginDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Paginated *Paginated `json:"paginated,omitempty"` + Success *bool `json:"success,omitempty"` +} + +// GetAllAssistantWhatsappDeploymentResponse defines model for GetAllAssistantWhatsappDeploymentResponse. +type GetAllAssistantWhatsappDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *[]AssistantWhatsappDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Paginated *Paginated `json:"paginated,omitempty"` + Success *bool `json:"success,omitempty"` +} + +// GetAssistantApiDeploymentResponse defines model for GetAssistantApiDeploymentResponse. +type GetAssistantApiDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *AssistantApiDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Success *bool `json:"success,omitempty"` +} + // GetAssistantDebuggerDeploymentResponse defines model for GetAssistantDebuggerDeploymentResponse. type GetAssistantDebuggerDeploymentResponse struct { Code *int32 `json:"code,omitempty"` @@ -221,6 +410,17 @@ type GetAssistantDebuggerDeploymentResponse struct { Success *bool `json:"success,omitempty"` } +// GetAssistantPhoneDeploymentResponse defines model for GetAssistantPhoneDeploymentResponse. +type GetAssistantPhoneDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *AssistantPhoneDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Success *bool `json:"success,omitempty"` +} + // GetAssistantResponse defines model for GetAssistantResponse. type GetAssistantResponse struct { Code *int32 `json:"code,omitempty"` @@ -232,6 +432,28 @@ type GetAssistantResponse struct { Success *bool `json:"success,omitempty"` } +// GetAssistantWebpluginDeploymentResponse defines model for GetAssistantWebpluginDeploymentResponse. +type GetAssistantWebpluginDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *AssistantWebpluginDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Success *bool `json:"success,omitempty"` +} + +// GetAssistantWhatsappDeploymentResponse defines model for GetAssistantWhatsappDeploymentResponse. +type GetAssistantWhatsappDeploymentResponse struct { + Code *int32 `json:"code,omitempty"` + Data *AssistantWhatsappDeployment `json:"data,omitempty"` + + // Error Platform error response details. `errorCode` is a stable platform error code. + // See `PlatformErrorCode` for documented code/message mappings. + Error *Error `json:"error,omitempty"` + Success *bool `json:"success,omitempty"` +} + // TextChatCompletePrompt defines model for TextChatCompletePrompt. type TextChatCompletePrompt struct { Prompt *[]TextPrompt `json:"prompt,omitempty"` @@ -252,8 +474,65 @@ type Variable struct { Type *string `json:"type,omitempty"` } +// GetAllAssistantApiDeploymentParams defines parameters for GetAllAssistantApiDeployment. +type GetAllAssistantApiDeploymentParams struct { + Page *uint32 `form:"page,omitempty" json:"page,omitempty"` + PageSize *uint32 `form:"pageSize,omitempty" json:"pageSize,omitempty"` + + // Criterias JSON encoded array of Criteria objects. + Criterias *string `form:"criterias,omitempty" json:"criterias,omitempty"` +} + +// GetAllAssistantDebuggerDeploymentParams defines parameters for GetAllAssistantDebuggerDeployment. +type GetAllAssistantDebuggerDeploymentParams struct { + Page *uint32 `form:"page,omitempty" json:"page,omitempty"` + PageSize *uint32 `form:"pageSize,omitempty" json:"pageSize,omitempty"` + + // Criterias JSON encoded array of Criteria objects. + Criterias *string `form:"criterias,omitempty" json:"criterias,omitempty"` +} + +// GetAllAssistantPhoneDeploymentParams defines parameters for GetAllAssistantPhoneDeployment. +type GetAllAssistantPhoneDeploymentParams struct { + Page *uint32 `form:"page,omitempty" json:"page,omitempty"` + PageSize *uint32 `form:"pageSize,omitempty" json:"pageSize,omitempty"` + + // Criterias JSON encoded array of Criteria objects. + Criterias *string `form:"criterias,omitempty" json:"criterias,omitempty"` +} + +// GetAllAssistantWebpluginDeploymentParams defines parameters for GetAllAssistantWebpluginDeployment. +type GetAllAssistantWebpluginDeploymentParams struct { + Page *uint32 `form:"page,omitempty" json:"page,omitempty"` + PageSize *uint32 `form:"pageSize,omitempty" json:"pageSize,omitempty"` + + // Criterias JSON encoded array of Criteria objects. + Criterias *string `form:"criterias,omitempty" json:"criterias,omitempty"` +} + +// GetAllAssistantWhatsappDeploymentParams defines parameters for GetAllAssistantWhatsappDeployment. +type GetAllAssistantWhatsappDeploymentParams struct { + Page *uint32 `form:"page,omitempty" json:"page,omitempty"` + PageSize *uint32 `form:"pageSize,omitempty" json:"pageSize,omitempty"` + + // Criterias JSON encoded array of Criteria objects. + Criterias *string `form:"criterias,omitempty" json:"criterias,omitempty"` +} + +// CreateAssistantApiDeploymentJSONRequestBody defines body for CreateAssistantApiDeployment for application/json ContentType. +type CreateAssistantApiDeploymentJSONRequestBody = CreateAssistantApiDeploymentRequest + // CreateAssistantDebuggerDeploymentJSONRequestBody defines body for CreateAssistantDebuggerDeployment for application/json ContentType. type CreateAssistantDebuggerDeploymentJSONRequestBody = CreateAssistantDebuggerDeploymentRequest +// CreateAssistantPhoneDeploymentJSONRequestBody defines body for CreateAssistantPhoneDeployment for application/json ContentType. +type CreateAssistantPhoneDeploymentJSONRequestBody = CreateAssistantPhoneDeploymentRequest + +// CreateAssistantWebpluginDeploymentJSONRequestBody defines body for CreateAssistantWebpluginDeployment for application/json ContentType. +type CreateAssistantWebpluginDeploymentJSONRequestBody = CreateAssistantWebpluginDeploymentRequest + +// CreateAssistantWhatsappDeploymentJSONRequestBody defines body for CreateAssistantWhatsappDeployment for application/json ContentType. +type CreateAssistantWhatsappDeploymentJSONRequestBody = CreateAssistantWhatsappDeploymentRequest + // CreateAssistantJSONRequestBody defines body for CreateAssistant for application/json ContentType. type CreateAssistantJSONRequestBody = CreateAssistantRequest diff --git a/openapi/common.gen.go b/openapi/common.gen.go index a3b79c0e..fd6df6e7 100644 --- a/openapi/common.gen.go +++ b/openapi/common.gen.go @@ -90,6 +90,13 @@ type AssistantDefinition struct { Version *string `json:"version,omitempty"` } +// Criteria defines model for Criteria. +type Criteria struct { + Key *string `json:"key,omitempty"` + Logic *string `json:"logic,omitempty"` + Value *string `json:"value,omitempty"` +} + // Error Platform error response details. `errorCode` is a stable platform error code. // See `PlatformErrorCode` for documented code/message mappings. type Error struct { @@ -126,6 +133,18 @@ type Metric struct { Value *string `json:"value,omitempty"` } +// Paginate defines model for Paginate. +type Paginate struct { + Page *uint32 `json:"page,omitempty"` + PageSize *uint32 `json:"pageSize,omitempty"` +} + +// Paginated defines model for Paginated. +type Paginated struct { + CurrentPage *uint32 `json:"currentPage,omitempty"` + TotalItem *uint32 `json:"totalItem,omitempty"` +} + // PlatformErrorCode Stable platform error code. // // Create Assistant: @@ -184,6 +203,116 @@ type Metric struct { // - `1004007`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. // - `1004008`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. // - `1004009`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. +// +// Create Assistant Phone Deployment: +// - `1005001`: invalid request - Invalid request. +// - `1005002`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1005003`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1005004`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1005005`: unable to create assistant phone deployment - Unable to create assistant phone deployment, please try again later. +// - `1005006`: invalid audio provider parameter - Please provide a valid audioProvider parameter. +// - `1005007`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. +// - `1005008`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. +// - `1005009`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. +// - `1005010`: missing phone_provider_name parameter - Please provide the required phoneProviderName parameter. +// +// Create Assistant API Deployment: +// - `1006001`: invalid request - Invalid request. +// - `1006002`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1006003`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1006004`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1006005`: unable to create assistant api deployment - Unable to create assistant api deployment, please try again later. +// - `1006006`: invalid audio provider parameter - Please provide a valid audioProvider parameter. +// - `1006007`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. +// - `1006008`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. +// - `1006009`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. +// +// Create Assistant Webplugin Deployment: +// - `1007001`: invalid request - Invalid request. +// - `1007002`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1007003`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1007004`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1007005`: unable to create assistant webplugin deployment - Unable to create assistant webplugin deployment, please try again later. +// - `1007006`: invalid audio provider parameter - Please provide a valid audioProvider parameter. +// - `1007007`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. +// - `1007008`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. +// - `1007009`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. +// +// Create Assistant WhatsApp Deployment: +// - `1008001`: invalid request - Invalid request. +// - `1008002`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1008003`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1008004`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1008005`: unable to create assistant whatsapp deployment - Unable to create assistant whatsapp deployment, please try again later. +// - `1008006`: invalid ideal_timeout parameter - Please provide idealTimeout between 15 and 120 seconds. +// - `1008007`: invalid ideal_timeout_backoff parameter - Please provide idealTimeoutBackoff between 0 and 5 times. +// - `1008008`: invalid max_session_duration parameter - Please provide maxSessionDuration between 180 and 600 seconds. +// - `1008009`: missing whatsapp_provider_name parameter - Please provide the required whatsappProviderName parameter. +// +// Get Assistant Debugger Deployment: +// - `1009001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1009002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1009003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1009004`: unable to get assistant debugger deployment - Unable to get assistant debugger deployment, please try again later. +// +// Get Assistant Phone Deployment: +// - `1010001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1010002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1010003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1010004`: unable to get assistant phone deployment - Unable to get assistant phone deployment, please try again later. +// +// Get Assistant API Deployment: +// - `1011001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1011002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1011003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1011004`: unable to get assistant api deployment - Unable to get assistant api deployment, please try again later. +// +// Get Assistant Webplugin Deployment: +// - `1012001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1012002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1012003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1012004`: unable to get assistant webplugin deployment - Unable to get assistant webplugin deployment, please try again later. +// +// Get Assistant WhatsApp Deployment: +// - `1013001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1013002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1013003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1013004`: unable to get assistant whatsapp deployment - Unable to get assistant whatsapp deployment, please try again later. +// +// Get All Assistant Debugger Deployment: +// - `1014001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1014002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1014003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1014004`: invalid request - Invalid request. +// - `1014005`: unable to get assistant debugger deployments - Unable to get assistant debugger deployments, please try again later. +// +// Get All Assistant Phone Deployment: +// - `1015001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1015002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1015003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1015004`: invalid request - Invalid request. +// - `1015005`: unable to get assistant phone deployments - Unable to get assistant phone deployments, please try again later. +// +// Get All Assistant API Deployment: +// - `1016001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1016002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1016003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1016004`: invalid request - Invalid request. +// - `1016005`: unable to get assistant api deployments - Unable to get assistant api deployments, please try again later. +// +// Get All Assistant Webplugin Deployment: +// - `1017001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1017002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1017003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1017004`: invalid request - Invalid request. +// - `1017005`: unable to get assistant webplugin deployments - Unable to get assistant webplugin deployments, please try again later. +// +// Get All Assistant WhatsApp Deployment: +// - `1018001`: unauthenticated request - Unauthenticated request, please try again with valid authentication. +// - `1018002`: missing authentication scope - Unauthenticated request, please try again with valid authentication. +// - `1018003`: invalid assistant_id parameter - Please provide a valid assistantId parameter. +// - `1018004`: invalid request - Invalid request. +// - `1018005`: unable to get assistant whatsapp deployments - Unable to get assistant whatsapp deployments, please try again later. type PlatformErrorCode = string // Uint64String defines model for Uint64String. diff --git a/pkg/errors/create_assistant_deployment.go b/pkg/errors/create_assistant_deployment.go index e3f172ed..dff158f6 100644 --- a/pkg/errors/create_assistant_deployment.go +++ b/pkg/errors/create_assistant_deployment.go @@ -17,6 +17,102 @@ const ( CreateAssistantDebuggerDeploymentInvalidIdealTimeoutCode ErrorCode = 1004007 CreateAssistantDebuggerDeploymentInvalidTimeoutBackoffCode ErrorCode = 1004008 CreateAssistantDebuggerDeploymentInvalidSessionDurationCode ErrorCode = 1004009 + + CreateAssistantPhoneDeploymentInvalidRequestCode ErrorCode = 1005001 + CreateAssistantPhoneDeploymentUnauthenticatedCode ErrorCode = 1005002 + CreateAssistantPhoneDeploymentMissingAuthScopeCode ErrorCode = 1005003 + CreateAssistantPhoneDeploymentInvalidAssistantIDCode ErrorCode = 1005004 + CreateAssistantPhoneDeploymentCreateDeploymentCode ErrorCode = 1005005 + CreateAssistantPhoneDeploymentInvalidAudioProviderCode ErrorCode = 1005006 + CreateAssistantPhoneDeploymentInvalidIdealTimeoutCode ErrorCode = 1005007 + CreateAssistantPhoneDeploymentInvalidTimeoutBackoffCode ErrorCode = 1005008 + CreateAssistantPhoneDeploymentInvalidSessionDurationCode ErrorCode = 1005009 + CreateAssistantPhoneDeploymentMissingPhoneProviderCode ErrorCode = 1005010 + + CreateAssistantApiDeploymentInvalidRequestCode ErrorCode = 1006001 + CreateAssistantApiDeploymentUnauthenticatedCode ErrorCode = 1006002 + CreateAssistantApiDeploymentMissingAuthScopeCode ErrorCode = 1006003 + CreateAssistantApiDeploymentInvalidAssistantIDCode ErrorCode = 1006004 + CreateAssistantApiDeploymentCreateDeploymentCode ErrorCode = 1006005 + CreateAssistantApiDeploymentInvalidAudioProviderCode ErrorCode = 1006006 + CreateAssistantApiDeploymentInvalidIdealTimeoutCode ErrorCode = 1006007 + CreateAssistantApiDeploymentInvalidTimeoutBackoffCode ErrorCode = 1006008 + CreateAssistantApiDeploymentInvalidSessionDurationCode ErrorCode = 1006009 + + CreateAssistantWebpluginDeploymentInvalidRequestCode ErrorCode = 1007001 + CreateAssistantWebpluginDeploymentUnauthenticatedCode ErrorCode = 1007002 + CreateAssistantWebpluginDeploymentMissingAuthScopeCode ErrorCode = 1007003 + CreateAssistantWebpluginDeploymentInvalidAssistantIDCode ErrorCode = 1007004 + CreateAssistantWebpluginDeploymentCreateDeploymentCode ErrorCode = 1007005 + CreateAssistantWebpluginDeploymentInvalidAudioProviderCode ErrorCode = 1007006 + CreateAssistantWebpluginDeploymentInvalidIdealTimeoutCode ErrorCode = 1007007 + CreateAssistantWebpluginDeploymentInvalidTimeoutBackoffCode ErrorCode = 1007008 + CreateAssistantWebpluginDeploymentInvalidSessionDurationCode ErrorCode = 1007009 + + CreateAssistantWhatsappDeploymentInvalidRequestCode ErrorCode = 1008001 + CreateAssistantWhatsappDeploymentUnauthenticatedCode ErrorCode = 1008002 + CreateAssistantWhatsappDeploymentMissingAuthScopeCode ErrorCode = 1008003 + CreateAssistantWhatsappDeploymentInvalidAssistantIDCode ErrorCode = 1008004 + CreateAssistantWhatsappDeploymentCreateDeploymentCode ErrorCode = 1008005 + CreateAssistantWhatsappDeploymentInvalidIdealTimeoutCode ErrorCode = 1008006 + CreateAssistantWhatsappDeploymentInvalidTimeoutBackoffCode ErrorCode = 1008007 + CreateAssistantWhatsappDeploymentInvalidSessionDurationCode ErrorCode = 1008008 + CreateAssistantWhatsappDeploymentMissingProviderCode ErrorCode = 1008009 + + GetAssistantDebuggerDeploymentUnauthenticatedCode ErrorCode = 1009001 + GetAssistantDebuggerDeploymentMissingAuthScopeCode ErrorCode = 1009002 + GetAssistantDebuggerDeploymentInvalidAssistantIDCode ErrorCode = 1009003 + GetAssistantDebuggerDeploymentGetDeploymentCode ErrorCode = 1009004 + + GetAssistantPhoneDeploymentUnauthenticatedCode ErrorCode = 1010001 + GetAssistantPhoneDeploymentMissingAuthScopeCode ErrorCode = 1010002 + GetAssistantPhoneDeploymentInvalidAssistantIDCode ErrorCode = 1010003 + GetAssistantPhoneDeploymentGetDeploymentCode ErrorCode = 1010004 + + GetAssistantApiDeploymentUnauthenticatedCode ErrorCode = 1011001 + GetAssistantApiDeploymentMissingAuthScopeCode ErrorCode = 1011002 + GetAssistantApiDeploymentInvalidAssistantIDCode ErrorCode = 1011003 + GetAssistantApiDeploymentGetDeploymentCode ErrorCode = 1011004 + + GetAssistantWebpluginDeploymentUnauthenticatedCode ErrorCode = 1012001 + GetAssistantWebpluginDeploymentMissingAuthScopeCode ErrorCode = 1012002 + GetAssistantWebpluginDeploymentInvalidAssistantIDCode ErrorCode = 1012003 + GetAssistantWebpluginDeploymentGetDeploymentCode ErrorCode = 1012004 + + GetAssistantWhatsappDeploymentUnauthenticatedCode ErrorCode = 1013001 + GetAssistantWhatsappDeploymentMissingAuthScopeCode ErrorCode = 1013002 + GetAssistantWhatsappDeploymentInvalidAssistantIDCode ErrorCode = 1013003 + GetAssistantWhatsappDeploymentGetDeploymentCode ErrorCode = 1013004 + + GetAllAssistantDebuggerDeploymentUnauthenticatedCode ErrorCode = 1014001 + GetAllAssistantDebuggerDeploymentMissingAuthScopeCode ErrorCode = 1014002 + GetAllAssistantDebuggerDeploymentInvalidAssistantIDCode ErrorCode = 1014003 + GetAllAssistantDebuggerDeploymentInvalidRequestCode ErrorCode = 1014004 + GetAllAssistantDebuggerDeploymentGetDeploymentCode ErrorCode = 1014005 + + GetAllAssistantPhoneDeploymentUnauthenticatedCode ErrorCode = 1015001 + GetAllAssistantPhoneDeploymentMissingAuthScopeCode ErrorCode = 1015002 + GetAllAssistantPhoneDeploymentInvalidAssistantIDCode ErrorCode = 1015003 + GetAllAssistantPhoneDeploymentInvalidRequestCode ErrorCode = 1015004 + GetAllAssistantPhoneDeploymentGetDeploymentCode ErrorCode = 1015005 + + GetAllAssistantApiDeploymentUnauthenticatedCode ErrorCode = 1016001 + GetAllAssistantApiDeploymentMissingAuthScopeCode ErrorCode = 1016002 + GetAllAssistantApiDeploymentInvalidAssistantIDCode ErrorCode = 1016003 + GetAllAssistantApiDeploymentInvalidRequestCode ErrorCode = 1016004 + GetAllAssistantApiDeploymentGetDeploymentCode ErrorCode = 1016005 + + GetAllAssistantWebpluginDeploymentUnauthenticatedCode ErrorCode = 1017001 + GetAllAssistantWebpluginDeploymentMissingAuthScopeCode ErrorCode = 1017002 + GetAllAssistantWebpluginDeploymentInvalidAssistantIDCode ErrorCode = 1017003 + GetAllAssistantWebpluginDeploymentInvalidRequestCode ErrorCode = 1017004 + GetAllAssistantWebpluginDeploymentGetDeploymentCode ErrorCode = 1017005 + + GetAllAssistantWhatsappDeploymentUnauthenticatedCode ErrorCode = 1018001 + GetAllAssistantWhatsappDeploymentMissingAuthScopeCode ErrorCode = 1018002 + GetAllAssistantWhatsappDeploymentInvalidAssistantIDCode ErrorCode = 1018003 + GetAllAssistantWhatsappDeploymentInvalidRequestCode ErrorCode = 1018004 + GetAllAssistantWhatsappDeploymentGetDeploymentCode ErrorCode = 1018005 ) var ( @@ -74,4 +170,496 @@ var ( Error: "invalid max_session_duration parameter", ErrorMessage: "Please provide maxSessionDuration between 180 and 600 seconds.", } + CreateAssistantPhoneDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantPhoneDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + CreateAssistantPhoneDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: CreateAssistantPhoneDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + CreateAssistantPhoneDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: CreateAssistantPhoneDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + CreateAssistantPhoneDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantPhoneDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + CreateAssistantPhoneDeploymentCreateDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: CreateAssistantPhoneDeploymentCreateDeploymentCode, + Error: "unable to create assistant phone deployment", + ErrorMessage: "Unable to create assistant phone deployment, please try again later.", + } + CreateAssistantPhoneDeploymentInvalidAudioProvider = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantPhoneDeploymentInvalidAudioProviderCode, + Error: "invalid audio provider parameter", + ErrorMessage: "Please provide a valid audioProvider parameter.", + } + CreateAssistantPhoneDeploymentInvalidIdealTimeout = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantPhoneDeploymentInvalidIdealTimeoutCode, + Error: "invalid ideal_timeout parameter", + ErrorMessage: "Please provide idealTimeout between 15 and 120 seconds.", + } + CreateAssistantPhoneDeploymentInvalidTimeoutBackoff = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantPhoneDeploymentInvalidTimeoutBackoffCode, + Error: "invalid ideal_timeout_backoff parameter", + ErrorMessage: "Please provide idealTimeoutBackoff between 0 and 5 times.", + } + CreateAssistantPhoneDeploymentInvalidSessionDuration = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantPhoneDeploymentInvalidSessionDurationCode, + Error: "invalid max_session_duration parameter", + ErrorMessage: "Please provide maxSessionDuration between 180 and 600 seconds.", + } + CreateAssistantPhoneDeploymentMissingPhoneProvider = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantPhoneDeploymentMissingPhoneProviderCode, + Error: "missing phone_provider_name parameter", + ErrorMessage: "Please provide the required phoneProviderName parameter.", + } + CreateAssistantApiDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantApiDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + CreateAssistantApiDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: CreateAssistantApiDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + CreateAssistantApiDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: CreateAssistantApiDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + CreateAssistantApiDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantApiDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + CreateAssistantApiDeploymentCreateDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: CreateAssistantApiDeploymentCreateDeploymentCode, + Error: "unable to create assistant api deployment", + ErrorMessage: "Unable to create assistant api deployment, please try again later.", + } + CreateAssistantApiDeploymentInvalidAudioProvider = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantApiDeploymentInvalidAudioProviderCode, + Error: "invalid audio provider parameter", + ErrorMessage: "Please provide a valid audioProvider parameter.", + } + CreateAssistantApiDeploymentInvalidIdealTimeout = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantApiDeploymentInvalidIdealTimeoutCode, + Error: "invalid ideal_timeout parameter", + ErrorMessage: "Please provide idealTimeout between 15 and 120 seconds.", + } + CreateAssistantApiDeploymentInvalidTimeoutBackoff = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantApiDeploymentInvalidTimeoutBackoffCode, + Error: "invalid ideal_timeout_backoff parameter", + ErrorMessage: "Please provide idealTimeoutBackoff between 0 and 5 times.", + } + CreateAssistantApiDeploymentInvalidSessionDuration = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantApiDeploymentInvalidSessionDurationCode, + Error: "invalid max_session_duration parameter", + ErrorMessage: "Please provide maxSessionDuration between 180 and 600 seconds.", + } + CreateAssistantWebpluginDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWebpluginDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + CreateAssistantWebpluginDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: CreateAssistantWebpluginDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + CreateAssistantWebpluginDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: CreateAssistantWebpluginDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + CreateAssistantWebpluginDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWebpluginDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + CreateAssistantWebpluginDeploymentCreateDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: CreateAssistantWebpluginDeploymentCreateDeploymentCode, + Error: "unable to create assistant webplugin deployment", + ErrorMessage: "Unable to create assistant webplugin deployment, please try again later.", + } + CreateAssistantWebpluginDeploymentInvalidAudioProvider = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWebpluginDeploymentInvalidAudioProviderCode, + Error: "invalid audio provider parameter", + ErrorMessage: "Please provide a valid audioProvider parameter.", + } + CreateAssistantWebpluginDeploymentInvalidIdealTimeout = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWebpluginDeploymentInvalidIdealTimeoutCode, + Error: "invalid ideal_timeout parameter", + ErrorMessage: "Please provide idealTimeout between 15 and 120 seconds.", + } + CreateAssistantWebpluginDeploymentInvalidTimeoutBackoff = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWebpluginDeploymentInvalidTimeoutBackoffCode, + Error: "invalid ideal_timeout_backoff parameter", + ErrorMessage: "Please provide idealTimeoutBackoff between 0 and 5 times.", + } + CreateAssistantWebpluginDeploymentInvalidSessionDuration = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWebpluginDeploymentInvalidSessionDurationCode, + Error: "invalid max_session_duration parameter", + ErrorMessage: "Please provide maxSessionDuration between 180 and 600 seconds.", + } + CreateAssistantWhatsappDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWhatsappDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + CreateAssistantWhatsappDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: CreateAssistantWhatsappDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + CreateAssistantWhatsappDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: CreateAssistantWhatsappDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + CreateAssistantWhatsappDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWhatsappDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + CreateAssistantWhatsappDeploymentCreateDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: CreateAssistantWhatsappDeploymentCreateDeploymentCode, + Error: "unable to create assistant whatsapp deployment", + ErrorMessage: "Unable to create assistant whatsapp deployment, please try again later.", + } + CreateAssistantWhatsappDeploymentInvalidIdealTimeout = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWhatsappDeploymentInvalidIdealTimeoutCode, + Error: "invalid ideal_timeout parameter", + ErrorMessage: "Please provide idealTimeout between 15 and 120 seconds.", + } + CreateAssistantWhatsappDeploymentInvalidTimeoutBackoff = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWhatsappDeploymentInvalidTimeoutBackoffCode, + Error: "invalid ideal_timeout_backoff parameter", + ErrorMessage: "Please provide idealTimeoutBackoff between 0 and 5 times.", + } + CreateAssistantWhatsappDeploymentInvalidSessionDuration = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWhatsappDeploymentInvalidSessionDurationCode, + Error: "invalid max_session_duration parameter", + ErrorMessage: "Please provide maxSessionDuration between 180 and 600 seconds.", + } + CreateAssistantWhatsappDeploymentMissingProvider = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: CreateAssistantWhatsappDeploymentMissingProviderCode, + Error: "missing whatsapp_provider_name parameter", + ErrorMessage: "Please provide the required whatsappProviderName parameter.", + } + GetAssistantDebuggerDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAssistantDebuggerDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantDebuggerDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAssistantDebuggerDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantDebuggerDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAssistantDebuggerDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAssistantDebuggerDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAssistantDebuggerDeploymentGetDeploymentCode, + Error: "unable to get assistant debugger deployment", + ErrorMessage: "Unable to get assistant debugger deployment, please try again later.", + } + GetAssistantPhoneDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAssistantPhoneDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantPhoneDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAssistantPhoneDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantPhoneDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAssistantPhoneDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAssistantPhoneDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAssistantPhoneDeploymentGetDeploymentCode, + Error: "unable to get assistant phone deployment", + ErrorMessage: "Unable to get assistant phone deployment, please try again later.", + } + GetAssistantApiDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAssistantApiDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantApiDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAssistantApiDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantApiDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAssistantApiDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAssistantApiDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAssistantApiDeploymentGetDeploymentCode, + Error: "unable to get assistant api deployment", + ErrorMessage: "Unable to get assistant api deployment, please try again later.", + } + GetAssistantWebpluginDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAssistantWebpluginDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantWebpluginDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAssistantWebpluginDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantWebpluginDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAssistantWebpluginDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAssistantWebpluginDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAssistantWebpluginDeploymentGetDeploymentCode, + Error: "unable to get assistant webplugin deployment", + ErrorMessage: "Unable to get assistant webplugin deployment, please try again later.", + } + GetAssistantWhatsappDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAssistantWhatsappDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantWhatsappDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAssistantWhatsappDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAssistantWhatsappDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAssistantWhatsappDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAssistantWhatsappDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAssistantWhatsappDeploymentGetDeploymentCode, + Error: "unable to get assistant whatsapp deployment", + ErrorMessage: "Unable to get assistant whatsapp deployment, please try again later.", + } + GetAllAssistantDebuggerDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAllAssistantDebuggerDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantDebuggerDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAllAssistantDebuggerDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantDebuggerDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantDebuggerDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAllAssistantDebuggerDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantDebuggerDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + GetAllAssistantDebuggerDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAllAssistantDebuggerDeploymentGetDeploymentCode, + Error: "unable to get assistant debugger deployments", + ErrorMessage: "Unable to get assistant debugger deployments, please try again later.", + } + GetAllAssistantPhoneDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAllAssistantPhoneDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantPhoneDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAllAssistantPhoneDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantPhoneDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantPhoneDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAllAssistantPhoneDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantPhoneDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + GetAllAssistantPhoneDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAllAssistantPhoneDeploymentGetDeploymentCode, + Error: "unable to get assistant phone deployments", + ErrorMessage: "Unable to get assistant phone deployments, please try again later.", + } + GetAllAssistantApiDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAllAssistantApiDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantApiDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAllAssistantApiDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantApiDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantApiDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAllAssistantApiDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantApiDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + GetAllAssistantApiDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAllAssistantApiDeploymentGetDeploymentCode, + Error: "unable to get assistant api deployments", + ErrorMessage: "Unable to get assistant api deployments, please try again later.", + } + GetAllAssistantWebpluginDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAllAssistantWebpluginDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantWebpluginDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAllAssistantWebpluginDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantWebpluginDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantWebpluginDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAllAssistantWebpluginDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantWebpluginDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + GetAllAssistantWebpluginDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAllAssistantWebpluginDeploymentGetDeploymentCode, + Error: "unable to get assistant webplugin deployments", + ErrorMessage: "Unable to get assistant webplugin deployments, please try again later.", + } + GetAllAssistantWhatsappDeploymentUnauthenticated = PlatformError{ + HTTPStatusCode: http.StatusUnauthorized, + Code: GetAllAssistantWhatsappDeploymentUnauthenticatedCode, + Error: "unauthenticated request", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantWhatsappDeploymentMissingAuthScope = PlatformError{ + HTTPStatusCode: http.StatusForbidden, + Code: GetAllAssistantWhatsappDeploymentMissingAuthScopeCode, + Error: "missing authentication scope", + ErrorMessage: "Unauthenticated request, please try again with valid authentication.", + } + GetAllAssistantWhatsappDeploymentInvalidAssistantID = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantWhatsappDeploymentInvalidAssistantIDCode, + Error: "invalid assistant_id parameter", + ErrorMessage: "Please provide a valid assistantId parameter.", + } + GetAllAssistantWhatsappDeploymentInvalidRequest = PlatformError{ + HTTPStatusCode: http.StatusBadRequest, + Code: GetAllAssistantWhatsappDeploymentInvalidRequestCode, + Error: "invalid request", + ErrorMessage: "Invalid request.", + } + GetAllAssistantWhatsappDeploymentGetDeployment = PlatformError{ + HTTPStatusCode: http.StatusInternalServerError, + Code: GetAllAssistantWhatsappDeploymentGetDeploymentCode, + Error: "unable to get assistant whatsapp deployments", + ErrorMessage: "Unable to get assistant whatsapp deployments, please try again later.", + } )