Example #1
0
def get():
    key = request.headers['key'] if 'key' in request.headers else '123'
    resultResponse = res.response(request.json["sentence"], context, key,
                                  False)
    responseDict = {}
    if resultResponse:
        responseDict['intent'] = resultResponse['intent']
        responseDict['probability'] = str(resultResponse['probability'])
        responseDict['response'] = resultResponse['response']
        responseDict['context_filter'] = resultResponse[
            'context_filter'] if 'context_filter' in resultResponse else ''
        #responseDict['context_filter'] =  resultResponse['context_filter'] if 'content_filter' in resultResponse else ''
        responseDict['context_set'] = resultResponse[
            'context_set'] if 'context_set' in resultResponse else ''
        responseDict['sentence'] = request.json["sentence"]
        responseDict['headers'] = {'auth-token': request.headers['auth-token']}

    print(resultResponse)
    result = getIntentResponse(responseDict, key)
    return result
    try:
        resp = jsonify(responseDict)
        return resp
    except:
        return {"error": "Internal Server Error"}
Example #2
0
def send(
    slack_client: SlackClient,
    bot_name: Optional[str],
    command: Optional[str],
    channel: Optional[str],
) -> Dict[str, str]:
    if command and channel:
        (request, payload) = response(command, bot_name)
        if request == UPLOAD_FILE:
            if exists(payload):
                with open(payload, "rb") as f:
                    return slack_client.api_call(
                        request,
                        channels=channel,
                        file=f,
                    )
            else:
                (request, payload) = (POST_MESSAGE, "Hmm... what?")
        return slack_client.api_call(request, channel=channel, text=payload)
    else:
        raise ApiError("Missing channel or command, closing connection.")
Example #3
0
def test():
    response = res.response(request.json["sentence"], context, '123', False)
    if response is not None:
        return jsonify(intent=response['intent'], prob=response['probability'])
    return None
 def test_response_to_hello_ok(self):
     response_greeting = response(self.__hello)
     hello_response = response_greeting.response_to_hello()
     self.assertEqual(hello_response, "Hello from the world!!")
 def test_alive(self):
     assert response("alive", None) == \
         (POST_MESSAGE, "I endure amongst the living.")
 def test_fallback(self):
     assert response("", None) == (
         POST_MESSAGE,
         "I don't know what that means. See what Bernar says.",
     )