Exemplo n.º 1
0
 def receive():
     payload = json.loads(request.data)
     sender_id = payload['user']['userId']
     intent = payload['inputs'][0]['intent']
     text = payload['inputs'][0]['rawInputs'][0]['query']
     if intent == 'actions.intent.MAIN':
         message = "<speak>Hello! <break time=\"1\"/> Welcome to the Google Assistant skill. You can start by saying hi."
     else:
         out = CollectingOutputChannel()
         on_new_message(UserMessage(text, out, sender_id))
         responses = [m["text"] for m in out.messages]
         message = responses[0]
     r = json.dumps({
         "conversationToken":
         "{\"state\":null,\"data\":{}}",
         "expectUserResponse":
         'true',
         "expectedInputs": [{
             "inputPrompt": {
                 "initialPrompts": [{
                     "ssml": message
                 }]
             },
             "possibleIntents": [{
                 "intent": "actions.intent.TEXT"
             }]
         }]
     })
     return r
Exemplo n.º 2
0
 def receive():
     payload = request.json
     sender_id = payload.get("sender", None)
     text = payload.get("message", None)
     out = CollectingOutputChannel()
     on_new_message(UserMessage(text, out, sender_id))
     responses = [m for _, m in out.messages]
     return jsonify(responses)
Exemplo n.º 3
0
        def receive():
            sender_id = self._extract_sender(request)
            text = self._extract_message(request)
            should_use_stream = utils.bool_arg("stream", default=False)

            if should_use_stream:
                return Response(self.stream_response(on_new_message, text,
                                                     sender_id),
                                content_type='text/event-stream')
            else:
                collector = CollectingOutputChannel()
                on_new_message(UserMessage(text, collector, sender_id))
                return jsonify(collector.messages)
Exemplo n.º 4
0
        def receive():
            payload = json.loads(request.data)
            sender_id = payload['user']['userId']
            intent = payload['inputs'][0]['intent']
            text = payload['inputs'][0]['rawInputs'][0]['query']
            if intent == 'actions.intent.MAIN':
                message = "<speak>Hello! <break time=\"1\"/> Welcome to the Rasa-powered Google Assistant skill. how can I help you today."
            else:
                out = CollectingOutputChannel()
                on_new_message(UserMessage(text, out, sender_id))
                #sb =[]
                responses = [m["text"] for m in out.messages]
                print(responses)

                seperator = ', '
                print(seperator.join(responses))
                mess = seperator.join(responses)
                #print("-----------------------"+responses[0])
                #print("--out.messages---------------------"+out.messages)
                #mess =[]

                #for x in range(len(responses[0])):
                # sb.append(str(x))
                #outstring =
                #print(outstring)

                #completemess = mess.append(out.messages[x].text)
                #print("------completemess-----"  + completemess)
                message = mess
                print(message)
            r = json.dumps({
                "conversationToken":
                "{\"state\":null,\"data\":{}}",
                "expectUserResponse":
                'true',
                "expectedInputs": [{
                    "inputPrompt": {
                        "initialPrompts": [{
                            "ssml": message
                        }]
                    },
                    "possibleIntents": [{
                        "intent": "actions.intent.TEXT"
                    }]
                }]
            })
            print(r)
            return r
Exemplo n.º 5
0
 def respond(self, request, sender_id):
     request.setHeader('Content-Type', 'application/json')
     request.setHeader('Access-Control-Allow-Origin', '*')
     request_params = request_parameters(request)
     if 'query' in request_params:
         message = request_params.pop('query')
     elif 'q' in request_params:
         message = request_params.pop('q')
     else:
         request.setResponseCode(400)
         return json.dumps({"error": "Invalid parse parameter specified"})
     try:
         out = CollectingOutputChannel()
         response = self.agent.handle_message(message, output_channel=out, sender_id=sender_id)
         request.setResponseCode(200)
         return json.dumps(response)
     except Exception as e:
         request.setResponseCode(500)
         logger.error("Caught an exception during "
                     "parse: {}".format(e), exc_info=1)
         return json.dumps({"error": "{}".format(e)})