diff --git a/chatbot/userdetails/app.py b/chatbot/userdetails/app.py new file mode 100644 index 0000000..9db6e9e --- /dev/null +++ b/chatbot/userdetails/app.py @@ -0,0 +1,52 @@ +import requests +from flask import Flask, request, jsonify,render_template +from flask_cors import CORS +import time +import pandas as pd +app = Flask(__name__) + +CORS(app) + +app.static_folder = 'static' + +# Define the Rasa server URL +rasa_server_url = "http://localhost:5005/webhooks/rest/webhook" + +@app.route("/") +def home(): + return render_template("index.html") + + +@app.route('/webhook', methods=['POST','GET']) +def webhook(): + user_ip = request.remote_addr + print("user ip is :",user_ip) + message = request.json['message'] + + + #recipient_id = request.json['recipient_id'] + + # Send the message to the Rasa server + rasa_response = requests.post(rasa_server_url, json={"message": message,"sender":user_ip}).json() + + # Return the Rasa response as a JSON object + print(rasa_response) + if len(rasa_response)==0: + return jsonify([ + { + "recipient_id": "default", + "text": "I'm sorry, I didn't understand that. Can you please rephrase?" + }]) + + else: + return jsonify(rasa_response) + + +@app.route("/get") +def get_bot_response(): + userText = request.args.get('msg') + return chatbot_response(userText) + + +if __name__ == '__main__': + app.run(host='0.0.0.0',port=5020) \ No newline at end of file diff --git a/chatbot/userdetails/config.yml b/chatbot/userdetails/config.yml new file mode 100644 index 0000000..3a43a4e --- /dev/null +++ b/chatbot/userdetails/config.yml @@ -0,0 +1,41 @@ +# The config recipe. +# https://rasa.com/docs/rasa/model-configuration/ +recipe: default.v1 + +# The assistant project unique identifier +# This default value must be replaced with a unique assistant name within your deployment +assistant_id: 20230807-114046-drab-rectangle + +# Configuration for Rasa NLU. +# https://rasa.com/docs/rasa/nlu/components/ +language: en + +pipeline: null +# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model. +# # If you'd like to customize it, uncomment and adjust the pipeline. +# # See https://rasa.com/docs/rasa/tuning-your-model for more information. +# - name: WhitespaceTokenizer +# - name: RegexFeaturizer +# - name: LexicalSyntacticFeaturizer +# - name: CountVectorsFeaturizer +# - name: CountVectorsFeaturizer +# analyzer: char_wb +# min_ngram: 1 +# max_ngram: 4 +# - name: DIETClassifier +# epochs: 100 +# constrain_similarities: true +# - name: EntitySynonymMapper +# - name: ResponseSelector +# epochs: 100 +# constrain_similarities: true +# - name: FallbackClassifier +# threshold: 0.3 +# ambiguity_threshold: 0.1 + +# Configuration for Rasa Core. +# https://rasa.com/docs/rasa/core/policies/ + + +policies: +- name: RulePolicy \ No newline at end of file diff --git a/chatbot/userdetails/credentials.yml b/chatbot/userdetails/credentials.yml new file mode 100644 index 0000000..e9f1291 --- /dev/null +++ b/chatbot/userdetails/credentials.yml @@ -0,0 +1,33 @@ +# This file contains the credentials for the voice & chat platforms +# which your bot is using. +# https://rasa.com/docs/rasa/messaging-and-voice-channels + +rest: +# # you don't need to provide anything here - this channel doesn't +# # require any credentials + + +#facebook: +# verify: "" +# secret: "" +# page-access-token: "" + +#slack: +# slack_token: "" +# slack_channel: "" +# slack_signing_secret: "" + +#socketio: +# user_message_evt: +# bot_message_evt: +# session_persistence: + +#mattermost: +# url: "https:///api/v4" +# token: "" +# webhook_url: "" + +# This entry is needed if you are using Rasa Enterprise. The entry represents credentials +# for the Rasa Enterprise "channel", i.e. Talk to your bot and Share with guest testers. +rasa: + url: "http://localhost:5002/api" diff --git a/chatbot/userdetails/domain.yml b/chatbot/userdetails/domain.yml new file mode 100644 index 0000000..85a2454 --- /dev/null +++ b/chatbot/userdetails/domain.yml @@ -0,0 +1,114 @@ +version: "3.1" + +intents: + - greet + - goodbye + - affirm + - deny + - mood_great + - mood_unhappy + - bot_challenge + - request_names + +entities: + - first_name + - last_name + - phone_num + - email_id + + +slots: + first_name: + type: text + influence_conversation: true + mappings: + - type: from_text + conditions: + - active_loop: name_form + requested_slot: first_name + last_name: + type: text + influence_conversation: true + mappings: + - type: from_text + conditions: + - active_loop: name_form + requested_slot: last_name + + phone_num: + type: text + influence_conversation: true + mappings: + - type: from_text + conditions: + - active_loop: name_form + requested_slot: phone_num + email_id: + type: text + influence_conversation: true + mappings: + - type: from_text + conditions: + - active_loop: name_form + requested_slot: email_id + + +forms: + name_form: + required_slots: + - first_name + - last_name + - phone_num + - email_id + + + +responses: + utter_greet: + - text: "Hey! How are you?" + + utter_cheer_up: + - text: "Here is something to cheer you up:" + image: "https://i.imgur.com/nGF1K8f.jpg" + + utter_did_that_help: + - text: "Did that help you?" + + utter_happy: + - text: "Great, carry on!" + + utter_goodbye: + - text: "Bye" + + utter_iamabot: + - text: "I am a bot, powered by Rasa." + + utter_ask_first_name: + - text: "What is your first name?" + + utter_ask_last_name: + - text: "What is your last name?" + + utter_ask_phone_num: + - text: "What is your phone number?" + + utter_ask_email_id: + - text: "What is your email id?" + + utter_submit: + - text: Ok. Thanks! + utter_slots_values: + - text: I will remember that your name is {first_name} {last_name} number {phone_num} and id is {email_id}! + + +actions: +- utter_slots_values +- utter_submit +- get_slot_data +- slots_to_clear + + + +session_config: + session_expiration_time: 60 + carry_over_slots_to_new_session: true diff --git a/chatbot/userdetails/endpoints.yml b/chatbot/userdetails/endpoints.yml new file mode 100644 index 0000000..d973280 --- /dev/null +++ b/chatbot/userdetails/endpoints.yml @@ -0,0 +1,42 @@ +# This file contains the different endpoints your bot can use. + +# Server where the models are pulled from. +# https://rasa.com/docs/rasa/model-storage#fetching-models-from-a-server + +#models: +# url: http://my-server.com/models/default_core@latest +# wait_time_between_pulls: 10 # [optional](default: 100) + +# Server which runs your custom actions. +# https://rasa.com/docs/rasa/custom-actions + +action_endpoint: + url: "http://localhost:5055/webhook" + +# Tracker store which is used to store the conversations. +# By default the conversations are stored in memory. +# https://rasa.com/docs/rasa/tracker-stores + +#tracker_store: +# type: redis +# url: +# port: +# db: +# password: +# use_ssl: + +#tracker_store: +# type: mongod +# url: +# db: +# username: +# password: + +# Event broker which all conversation events should be streamed to. +# https://rasa.com/docs/rasa/event-brokers + +#event_broker: +# url: localhost +# username: username +# password: password +# queue: queue