예제 #1
0
 def post(self, request, format=None):
     serializer = MessageSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         r = query_dialogflow(serializer.data.get('text'))
         json_response = r.json()
         response = json_response.get('result', {}).get(
             "fulfillment", {}).get("speech", "Je n'ai pas compris...")
         return Response({"speech_answer": response},
                         status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #2
0
def post_user_message(request):
    """
    post ->  dodaje poruku za odredenog usera od usera
    :param request:
    :return:
    """
    if request.method == "POST":
        serializer = MessageSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
예제 #3
0
    def post(self, request):

        serializer = MessageSerializer(data=request.data)
        serializer.is_valid()
        message = serializer.save()
        # 2018-09-29 15:04:34.380000+00:00
        return Response()
예제 #4
0
    def post(self, request, **kwargs):
        data = request.DATA

        serializer = MessageSerializer(data=data)

        if serializer.is_valid():
            message = serializer.save()
            sender = message.sender.first_name if message.sender.first_name else message.sender.username

            # Send notification to APNS
            send_push_notification(user=message.receiver,
                                   notification="From {}: {}".format(
                                       sender, message.text),
                                   type="message",
                                   obj_id=message.thread.id)

            return Response(message.to_dict(), status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)