Skip to content

Commit

Permalink
Merge pull request #413 from weni-ai/feature/update-contacts
Browse files Browse the repository at this point in the history
feat: adding endpoint to edit contacts
  • Loading branch information
ericosta-dev authored Oct 24, 2024
2 parents 0a8950e + 0c495c1 commit 023d5fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions chats/apps/api/v1/projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def get_user_email(self, linked_contact: LinkContact) -> str:


class ProjectFlowContactSerializer(serializers.Serializer):
uuid = serializers.CharField(required=False)
name = serializers.CharField()
language = serializers.CharField(required=False, max_length=3)
urns = serializers.ListField(child=serializers.CharField(), max_length=100)
Expand Down
27 changes: 27 additions & 0 deletions chats/apps/api/v1/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,33 @@ def create_contacts(self, request, *args, **kwargs):
)
return Response(contact_response_data, response_status)

@action(detail=True, methods=["PUT"], url_name="edit_contact")
def edit_contact(self, request, *args, **kwargs):
project = self.get_object()
serializer = ProjectFlowContactSerializer(data=request.data)
flows_client = FlowRESTClient()

if serializer.is_valid() is False:
return Response(
{"Detail": "Data not valid."},
status.HTTP_400_BAD_REQUEST,
)

contact_uuid = request.data.get("uuid")
data = serializer.validated_data

contact_response = flows_client.create_contact(
project=project, data=data, contact_id=contact_uuid
)

contact_response_data = contact_response.json()
response_status = (
status.HTTP_200_OK
if contact_response.status_code in [200, 201]
else status.HTTP_400_BAD_REQUEST
)
return Response(contact_response_data, response_status)

@action(detail=True, methods=["GET"], url_name="groups")
def list_groups(self, request, *args, **kwargs):
project = self.get_object()
Expand Down

0 comments on commit 023d5fa

Please sign in to comment.