def chatbotReply():
    # context = chatbot.context
    message = request.get_json()
    id = message['id']
    messageText = message['message']
    userId = message['userId']
    #write user message to database
    write_message(id, userId, messageText, False, datetime.datetime.now())
    reply = chatbot.response(messageText, userId)
    date_handler = lambda obj: (
        obj.isoformat()
        if isinstance(obj, (datetime.datetime, datetime.date))
        else None
    )
    ident = json.dumps(datetime.datetime.now(), default=date_handler).strip('"')
    # return jsonify({"userId": 1, "id": ident, "message": reply, "isBot": True, "context": context}), 200
    return jsonify({"userId": 1, "id": ident, "message": reply, "isBot": True}), 200
Exemple #2
0
    def test_response(self):
        self.assertIn(
            Bankingchatbot.response('hi', 1),
            ["Hello", "Good to see you", "Hi there, how can I help?"])
        self.assertIn(
            Bankingchatbot.response('hi there', 1),
            ["Hello", "Good to see you", "Hi there, how can I help?"])
        self.assertNotIn(
            Bankingchatbot.response('how are you', 1),
            ["Hello", "Good to see you", "Hi there, how can I help?"])
        self.assertNotIn(
            Bankingchatbot.response("I agree", 1),
            ["Hello", "Good to see you", "Hi there, how can I help?"])

        self.assertIn(Bankingchatbot.response('by bye', 1), [
            "See you!", "Have a nice day", "Bye! Come back again soon.",
            "Great chatting with you"
        ])
        self.assertIn(Bankingchatbot.response('see you soon', 1), [
            "See you!", "Have a nice day", "Bye! Come back again soon.",
            "Great chatting with you"
        ])
        self.assertNotIn(Bankingchatbot.response('hi', 1), [
            "See you!", "Have a nice day", "Bye! Come back again soon.",
            "Great chatting with you"
        ])
        self.assertNotIn(Bankingchatbot.response('call to bank', 1), [
            "See you!", "Have a nice day", "Bye! Come back again soon.",
            "Great chatting with you"
        ])

        self.assertIn(Bankingchatbot.response('thanks', 1),
                      ["Happy to help!", "Any time!", "Thank you!"])
        self.assertIn(Bankingchatbot.response('thank you very much', 1),
                      ["Happy to help!", "Any time!", "Thank you!"])
        self.assertNotIn(Bankingchatbot.response('adfadfa', 1),
                         ["Happy to help!", "Any time!", "Thank you!"])
        self.assertNotIn(Bankingchatbot.response('what you can do', 1),
                         ["Happy to help!", "Any time!", "Thank you!"])

        self.assertEqual(Bankingchatbot.response("actually I don't know", 1),
                         "that's fine !")
        self.assertEqual(Bankingchatbot.response('no,absolutely not', 1),
                         "that's fine !")
        self.assertNotEqual(Bankingchatbot.response("thank you", 1),
                            "that's fine !")
        self.assertNotEqual(Bankingchatbot.response("I hate you", 1),
                            "that's fine !")

        self.assertEqual(Bankingchatbot.response('okay', 1),
                         "Is there anything to help with ?")
        self.assertEqual(Bankingchatbot.response("it is fine", 1),
                         "Is there anything to help with ?")
        self.assertNotEqual(Bankingchatbot.response('ooookaaay', 1),
                            "Is there anything to help with ?")
        self.assertNotEqual(Bankingchatbot.response("how are you", 1),
                            "Is there anything to help with ?")

        self.assertIn(Bankingchatbot.response('accept', 1), [
            "let's move forward", "we can carry on..",
            "you are right! Lets continue.."
        ])
        self.assertIn(Bankingchatbot.response('I agree', 1), [
            "let's move forward", "we can carry on..",
            "you are right! Lets continue.."
        ])
        self.assertNotIn(Bankingchatbot.response('i want to dance', 1), [
            "let's move forward", "we can carry on..",
            "you are right! Lets continue.."
        ])
        self.assertNotIn(Bankingchatbot.response('no thanks', 1), [
            "let's move forward", "we can carry on..",
            "you are right! Lets continue.."
        ])

        self.assertEqual(Bankingchatbot.response('just stop it', 1),
                         "okay! Is there anything to help with ?")
        self.assertEqual(Bankingchatbot.response("i'm quit", 1),
                         "okay! Is there anything to help with ?")
        self.assertNotEqual(Bankingchatbot.response('asdfadf', 1),
                            "okay! Is there anything to help with ?")
        self.assertNotEqual(Bankingchatbot.response('hi there', 1),
                            "okay! Is there anything to help with ?")

        self.assertIn(Bankingchatbot.response('I want to do a job soon', 1),
                      ["Sorry, can't understand you", "Not sure I understand"])
        self.assertIn(Bankingchatbot.response('asdfdafdf', 1),
                      ["Sorry, can't understand you", "Not sure I understand"])
        self.assertNotIn(
            Bankingchatbot.response('what you can do', 1),
            ["Sorry, can't understand you", "Not sure I understand"])
        self.assertNotIn(
            Bankingchatbot.response('thanks', 1),
            ["Sorry, can't understand you", "Not sure I understand"])

        self.assertEqual(
            Bankingchatbot.response('what are the options you have', 1),
            "Here are some of the things I can do.\n1.View personal details of your account.\n   Eg: Show my personal details.\n2.View your current account balance.\n   Eg:Show my acount balance.\n3.View your transactions information.\n   Eg:show my account transaction history.\n4.Transfer money to your friend.\n   Eg: I want to transfer money.\n5.Make a bill payment with your bank account.\n   Eg: I want to pay a bill.\n6.Report a Complain about your banking service.\n   Eg: I want to report a complain."
        )
        self.assertEqual(
            Bankingchatbot.response('What you can do', 1),
            "Here are some of the things I can do.\n1.View personal details of your account.\n   Eg: Show my personal details.\n2.View your current account balance.\n   Eg:Show my acount balance.\n3.View your transactions information.\n   Eg:show my account transaction history.\n4.Transfer money to your friend.\n   Eg: I want to transfer money.\n5.Make a bill payment with your bank account.\n   Eg: I want to pay a bill.\n6.Report a Complain about your banking service.\n   Eg: I want to report a complain."
        )
        self.assertNotEqual(
            Bankingchatbot.response('what is my account number', 1),
            "Here are some of the things I can do.\n1.View personal details of your account.\n   Eg: Show my personal details.\n2.View your current account balance.\n   Eg:Show my acount balance.\n3.View your transactions information.\n   Eg:show my account transaction history.\n4.Transfer money to your friend.\n   Eg: I want to transfer money.\n5.Make a bill payment with your bank account.\n   Eg: I want to pay a bill.\n6.Report a Complain about your banking service.\n   Eg: I want to report a complain."
        )
        self.assertNotEqual(
            Bankingchatbot.response('what is my name', 1),
            "Here are some of the things I can do.\n1.View personal details of your account.\n   Eg: Show my personal details.\n2.View your current account balance.\n   Eg:Show my acount balance.\n3.View your transactions information.\n   Eg:show my account transaction history.\n4.Transfer money to your friend.\n   Eg: I want to transfer money.\n5.Make a bill payment with your bank account.\n   Eg: I want to pay a bill.\n6.Report a Complain about your banking service.\n   Eg: I want to report a complain."
        )
Exemple #3
0
    def test_response(self):
        self.assertIn(
            Bankingchatbot.response('hi', 1),
            ["Hello", "Good to see you", "Hi there, how can I help?"])
        self.assertIn(
            Bankingchatbot.response('hi there', 1),
            ["Hello", "Good to see you", "Hi there, how can I help?"])
        self.assertNotIn(
            Bankingchatbot.response('how are you', 1),
            ["Hello", "Good to see you", "Hi there, how can I help?"])
        self.assertNotIn(
            Bankingchatbot.response("I agree", 1),
            ["Hello", "Good to see you", "Hi there, how can I help?"])

        self.assertIn(Bankingchatbot.response('by bye', 1), [
            "See you!", "Have a nice day", "Bye! Come back again soon.",
            "Great chatting with you"
        ])
        self.assertIn(Bankingchatbot.response('see you soon', 1), [
            "See you!", "Have a nice day", "Bye! Come back again soon.",
            "Great chatting with you"
        ])
        self.assertNotIn(Bankingchatbot.response('hi', 1), [
            "See you!", "Have a nice day", "Bye! Come back again soon.",
            "Great chatting with you"
        ])
        self.assertNotIn(Bankingchatbot.response('call to bank', 1), [
            "See you!", "Have a nice day", "Bye! Come back again soon.",
            "Great chatting with you"
        ])

        self.assertIn(Bankingchatbot.response('thanks', 1),
                      ["Happy to help!", "Any time!", "Thank you!"])
        self.assertIn(Bankingchatbot.response('thank you very much', 1),
                      ["Happy to help!", "Any time!", "Thank you!"])
        self.assertNotIn(Bankingchatbot.response('adfadfa', 1),
                         ["Happy to help!", "Any time!", "Thank you!"])
        self.assertNotIn(Bankingchatbot.response('what you can do', 1),
                         ["Happy to help!", "Any time!", "Thank you!"])

        self.assertEqual(Bankingchatbot.response("actually I don't know", 1),
                         "that's fine !")
        self.assertEqual(Bankingchatbot.response('no,absolutely not', 1),
                         "that's fine !")
        self.assertNotEqual(Bankingchatbot.response("thank you", 1),
                            "that's fine !")
        self.assertNotEqual(Bankingchatbot.response("I hate you", 1),
                            "that's fine !")

        self.assertEqual(Bankingchatbot.response('okay', 1),
                         "Is there anything to help with ?")
        self.assertEqual(Bankingchatbot.response("it is fine", 1),
                         "Is there anything to help with ?")
        self.assertNotEqual(Bankingchatbot.response('ooookaaay', 1),
                            "Is there anything to help with ?")
        self.assertNotEqual(Bankingchatbot.response("how are you", 1),
                            "Is there anything to help with ?")

        self.assertIn(Bankingchatbot.response('accept', 1), [
            "let's move forward", "we can carry on..",
            "you are right! Lets continue.."
        ])
        self.assertIn(Bankingchatbot.response('I agree', 1), [
            "let's move forward", "we can carry on..",
            "you are right! Lets continue.."
        ])
        self.assertNotIn(Bankingchatbot.response('i want to dance', 1), [
            "let's move forward", "we can carry on..",
            "you are right! Lets continue.."
        ])
        self.assertNotIn(Bankingchatbot.response('no thanks', 1), [
            "let's move forward", "we can carry on..",
            "you are right! Lets continue.."
        ])

        self.assertEqual(Bankingchatbot.response('just stop it', 1),
                         "okay! Is there anything to help with ?")
        self.assertEqual(Bankingchatbot.response("i'm quit", 1),
                         "okay! Is there anything to help with ?")
        self.assertNotEqual(Bankingchatbot.response('asdfadf', 1),
                            "okay! Is there anything to help with ?")
        self.assertNotEqual(Bankingchatbot.response('hi there', 1),
                            "okay! Is there anything to help with ?")

        self.assertIn(Bankingchatbot.response('I want to do a job soon', 1),
                      ["Sorry, can't understand you", "Not sure I understand"])
        self.assertIn(Bankingchatbot.response('asdfdafdf', 1),
                      ["Sorry, can't understand you", "Not sure I understand"])
        self.assertNotIn(
            Bankingchatbot.response('what you can do', 1),
            ["Sorry, can't understand you", "Not sure I understand"])
        self.assertNotIn(
            Bankingchatbot.response('thanks', 1),
            ["Sorry, can't understand you", "Not sure I understand"])

        self.assertIn(
            Bankingchatbot.response('what are the options you have', 1), [
                "I can guide you to do money transferring, online bill payments, show your account details as well as report a complaint",
                "Offering support for do money transferring, online bill payments, show your account details as well as report a complaint"
            ])
        self.assertIn(Bankingchatbot.response('What you can do', 1), [
            "I can guide you to do money transferring, online bill payments, show your account details as well as report a complaint",
            "Offering support for do money transferring, online bill payments, show your account details as well as report a complaint"
        ])
        self.assertNotIn(
            Bankingchatbot.response('what is my account number', 1), [
                "I can guide you to do money transferring, online bill payments, show your account details as well as report a complaint",
                "Offering support for do money transferring, online bill payments, show your account details as well as report a complaint"
            ])
        self.assertNotIn(Bankingchatbot.response('what is my name', 1), [
            "I can guide you to do money transferring, online bill payments, show your account details as well as report a complaint",
            "Offering support for do money transferring, online bill payments, show your account details as well as report a complaint"
        ])