diff --git a/chatbot/app.py b/chatbot/app.py new file mode 100644 index 0000000..ec71523 --- /dev/null +++ b/chatbot/app.py @@ -0,0 +1,121 @@ +import requests +from flask import Flask, request, jsonify,render_template +from flask_cors import CORS + +app = Flask(__name__) + + + +CORS(app) + +# import nltk +# nltk.download('popular') +# from nltk.stem import WordNetLemmatizer +# lemmatizer = WordNetLemmatizer() +# import pickle +# import numpy as np + +# from keras.models import load_model +# model = load_model('model.h5') +# import json +# import random +# intents = json.loads(open('data.json').read()) +# words = pickle.load(open('texts.pkl','rb')) +# classes = pickle.load(open('labels.pkl','rb')) + +# def clean_up_sentence(sentence): +# # tokenize the pattern - split words into array +# sentence_words = nltk.word_tokenize(sentence) +# # stem each word - create short form for word +# sentence_words = [lemmatizer.lemmatize(word.lower()) for word in sentence_words] +# return sentence_words + +# # return bag of words array: 0 or 1 for each word in the bag that exists in the sentence + +# def bow(sentence, words, show_details=True): +# # tokenize the pattern +# sentence_words = clean_up_sentence(sentence) +# # bag of words - matrix of N words, vocabulary matrix +# bag = [0]*len(words) +# for s in sentence_words: +# for i,w in enumerate(words): +# if w == s: +# # assign 1 if current word is in the vocabulary position +# bag[i] = 1 +# if show_details: +# print ("found in bag: %s" % w) +# return(np.array(bag)) + +# def predict_class(sentence, model): +# # filter out predictions below a threshold +# p = bow(sentence, words,show_details=False) +# res = model.predict(np.array([p]))[0] +# ERROR_THRESHOLD = 0.25 +# results = [[i,r] for i,r in enumerate(res) if r>ERROR_THRESHOLD] +# # sort by strength of probability +# results.sort(key=lambda x: x[1], reverse=True) +# return_list = [] +# for r in results: +# return_list.append({"intent": classes[r[0]], "probability": str(r[1])}) +# return return_list + +# def getResponse(ints, intents_json): +# tag = ints[0]['intent'] +# list_of_intents = intents_json['intents'] +# for i in list_of_intents: +# if(i['tag']== tag): +# result = random.choice(i['responses']) +# break +# return result + +# def chatbot_response(msg): +# ints = predict_class(msg, model) +# res = getResponse(ints, intents) +# return res + + + +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(): + message = request.json['message'] + # message =request.args.get('msg') + + # Send the message to the Rasa server + rasa_response = requests.post(rasa_server_url, json={"message": message}).json() + + # for d in rasa_response: + # a=d["text"] + + # 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/config.yml b/chatbot/config.yml new file mode 100644 index 0000000..4d51ca5 --- /dev/null +++ b/chatbot/config.yml @@ -0,0 +1,38 @@ +recipe: default.v1 +assistant_id: 20230411-174114-maximum-louver +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 +policies: null +# # No configuration for policies was provided. The following default policies were used to train your model. +# # If you'd like to customize them, uncomment and adjust the policies. +# # See https://rasa.com/docs/rasa/policies for more information. +# - name: MemoizationPolicy +# - name: RulePolicy +# - name: UnexpecTEDIntentPolicy +# max_history: 5 +# epochs: 100 +# - name: TEDPolicy +# max_history: 5 +# epochs: 100 +# constrain_similarities: true diff --git a/chatbot/credentials.yml b/chatbot/credentials.yml new file mode 100644 index 0000000..c2b07ea --- /dev/null +++ b/chatbot/credentials.yml @@ -0,0 +1,38 @@ +# 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 + + +# rest: +# # You can customize the webhook URL to include the user's ID as a parameter +# webhook_url: "http://localhost:5005/webhooks/rest/webhook?recipient_id={sender_id}" + +#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. + + + diff --git a/chatbot/domain.yml b/chatbot/domain.yml new file mode 100644 index 0000000..d83f5c2 --- /dev/null +++ b/chatbot/domain.yml @@ -0,0 +1,150 @@ +intents: + - greet + - goodbye + - affirm + - deny + - mood_great + - mood_unhappy + - bot_challenge + - question1 + - question3 + - question4 + - question5 + - question6 + - docs + - video + - connect_support + - noconnect_support + + +entities: + - content_type + +slots: + content_type: + type: text + mappings: + - type: from_entity + entity: content_type + + +responses: + utter_cheer_up: + - image: https://i.imgur.com/nGF1K8f.jpg + text: 'Here is something to cheer you up:' + utter_did_that_help: + - text: Did that help you? + utter_goodbye: + - text: Bye + utter_greet: + - text: Hey! How are you? + utter_happy: + - text: Great, carry on! + utter_iamabot: + - text: I am a bot, powered by Rasa. + utter_question1_1: + - text: We have explained the process of changing the old to the new manager for + customers in DMS, Follow the below procedures. 1) Open DMS--->Go to the change + manager module--->Click on the create option--->Fill in the details--->Save--->Confirm. + 2) customer module--then select customer--edit the sale manager's name to + the required employee and save to reflect in his login + utter_question1_2: + - text: To change the manager for customers in DMS, first, open the DMS system, + then navigate to the "change manager" module, click on the "create" option, + fill in the necessary details, save the changes, and confirm the update. Next, + go to the "customer" module, select the relevant customer, edit the sales + manager's name to the desired employee, and save the changes to reflect the + update in their login + utter_question1_3: + - text: The process of changing the manager for customers in DMS involves several + steps. First, access the DMS system and open the "change manager" module. + From there, click on the "create" option, provide the required details, and + save the changes. Once the update is confirmed, navigate to the "customer" + module, select the appropriate customer, modify the sales manager's name to + the preferred employee, and save the changes to ensure that it reflects in + their login. + + utter_question3_1: + - text: Customers module----> enter the customer name----> Open details----> click + on sales manager---->edit---->save. + utter_question3_2: + - text: If you want to change the sales manager for a particular customer in DMS, + go to the Customers module and enter the name of the customer. Then, open + the customer's details, find the "Sales Manager" section, click on it, choose + the "Edit" option to modify the sales manager's name, enter the new name, + and save the changes. + utter_question3_3: + - text: nan + utter_question4_1: + - text: Please find the below process to change the Customer Segment tag Customer + module--->Select Particular Customer----->click on details------>check on + + to change the LOB tags. + utter_question4_2: + - text: If you need to change the Customer Segment tag for a particular customer + in DMS, start by accessing the Customer module, selecting the relevant customer, + and clicking on their details. Once you are in the customer's details, locate + the "+" symbol to modify the LOB tags and update the Customer Segment tag. + utter_question4_3: + - text: To modify the Customer Segment tag for a specific customer in DMS, go + to the Customer module, find the customer whose tag you want to change, and + open their details. Then, click on the "+" symbol to add or remove LOB tags, + and make the necessary changes to the Customer Segment tag. + utter_question5_1: + - text: We have explained the process of checking the EB-invoice report through + remote session & follow the below procedure. Open DMS-----> click on reports----->open + EB- invoice report---->check. + utter_question5_2: + - text: To verify the EB-invoice report through a remote session, follow these + steps first, access the DMS platform, then navigate to the "reports" section + and click on the "EB-invoice report." Finally, carefully review the report + to ensure all necessary information is present and accurate. + utter_question5_3: + - text: The process of remotely checking the EB-invoice report can be accomplished + in a few simple steps. Begin by logging into the DMS platform and selecting + the "reports" option. From there, click on the "EB-invoice report" and review + the contents to confirm its accuracy. + utter_question6_1: + - text: Please find the below process to add branchto employee Employee module------>Search + the employee name ---->Open employee----->click on official Widget------>click + on branches +check on------->click on plus symbol----->select the branch from + the dropdown ------->save. + utter_question6_2: + - text: To assign a branch to an employee, follow these steps first, access the + Employee module and search for the employee's name. Next, open the employee's + profile and click on the Official Widget. From there, click on the "branches" + option and check the box to enable it. Then, click on the plus symbol and + select the appropriate branch from the dropdown menu. Finally, click on "save" + to confirm the changes. + utter_question6_3: + - text: Adding a branch to an employee is a simple process that involves accessing + the Employee module and searching for the employee in question. Once you've + found their profile, open it and click on the Official Widget, followed by + the "branches" option. Check the box to enable branches, then click the plus + symbol and select the appropriate branch from the dropdown list. Be sure to + save your changes before exiting the page. + + utter_blogs: + - text: "great carry on" + + utter_video: + - text: "do you want me to connect you to support team" + + + utter_connect_support: + - text: "Im conneting you to support team" + + utter_noconnect_support: + - text: "great carry on" + +actions: + - action_service + - action_suport_service + # - action_save_conersation + # - action_clear_conversation + + + +session_config: + carry_over_slots_to_new_session: true + session_expiration_time: 60 +version: '3.1' diff --git a/chatbot/endpoints.yml b/chatbot/endpoints.yml new file mode 100644 index 0000000..1348f02 --- /dev/null +++ b/chatbot/endpoints.yml @@ -0,0 +1,46 @@ +# 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?recipient_id={sender_id}" + +# 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 + + + +