From 847303942a60da7c9f8dafa2b77050b40e811338 Mon Sep 17 00:00:00 2001 From: ajinkyaghodake123 Date: Mon, 17 Aug 2020 12:57:41 +0530 Subject: [PATCH 1/2] slot filling with suggestions --- bot/actions.py | 205 +++- bot/config.yml | 1 + bot/data/grades.txt | 10 +- bot/data/nlu.md | 16 +- bot/data/stories.md | 14 +- bot/domain.yml | 87 +- bot/resources/boards.json | 57 + bot/resources/boards_api.json | 58 + bot/resources/grades.json | 66 ++ bot/resources/mediums.json | 26 + router/api/rasa.core/botwebhook.js | 23 +- router/appRest.js | 8 + router/config/chatflow.js | 252 ++++- router/config/literals.js | 1308 +++++++++++++++++++++- router/controllers/rasaCoreController.js | 3 + 15 files changed, 2073 insertions(+), 61 deletions(-) create mode 100644 bot/resources/boards.json create mode 100644 bot/resources/boards_api.json create mode 100644 bot/resources/grades.json create mode 100644 bot/resources/mediums.json diff --git a/bot/actions.py b/bot/actions.py index 32493ee..227bb68 100644 --- a/bot/actions.py +++ b/bot/actions.py @@ -7,10 +7,15 @@ from typing import Any, Text, Dict, List from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher +from rasa_sdk.forms import FormAction import spacy +from rasa_sdk.events import SlotSet +import json +import os.path +import requests # # -nlp = spacy.load('en_core_web_sm') +nlp = spacy.load('en_core_web_sm') class ActionSubjectCourses(Action): @@ -23,14 +28,14 @@ def run(self, dispatcher: CollectingDispatcher, print('running action_subject_courses') dispatcher.utter_message(template="utter_fetching_data") print(tracker.latest_message.get('entities')) - elements = [{"type":"subject_courses","entities":tracker.latest_message.get('entities'), "intent" : "subject_courses"}] + elements = [{"type": "subject_courses", "entities": tracker.latest_message.get( + 'entities'), "intent": "subject_courses"}] dispatcher.utter_message(json_message=elements) #dispatcher.utter_custom_message(*elements) #dispatcher.utter_custom_json(elements) return [] - class FallbackAction(Action): def name(self): return "fallback_action" @@ -39,15 +44,199 @@ def run(self, dispatcher, tracker, domain): intent_ranking = tracker.latest_message.get('intent_ranking', []) doc = nlp(tracker.latest_message.get('text')) nouns = [] - adjs = [] + adjs = [] for token in doc: if token.pos_ == 'NOUN': nouns.append(token.text) if token.pos_ == 'ADJ': adjs.append(token.text) - if len(intent_ranking) > 0 : - elements = [{"type":"low_confidence","entities":nouns, "adj":adjs, "intent" : "low_confidence"}] + if len(intent_ranking) > 0: + elements = [{"type": "low_confidence", "entities": nouns, + "adj": adjs, "intent": "low_confidence"}] dispatcher.utter_message(json_message=elements) - else : - elements = [{"type":"low_confidence","entities":nouns, "adj":adjs, "intent" : "low_confidence"}] + else: + elements = [{"type": "low_confidence", "entities": nouns, + "adj": adjs, "intent": "low_confidence"}] dispatcher.utter_message(json_message=elements) + + +class ActionContentForm(FormAction): + def name(self) -> Text: + return "content_form" + + @staticmethod + def required_slots(tracker: Tracker) -> List[Text]: + return ["board", "medium", "grade"] + + def submit(self, dispatcher: CollectingDispatcher, + tracker: Tracker, + domain: Dict[Text, Any]) -> List[Dict]: + base_url = "https://diksha.gov.in/explore" + + board_url = "https://staging.ntp.net.in/api/channel/v1/read/0126632859575746566" + + filter_url = "https://staging.ntp.net.in/api/framework/v1/read/ka_k-12_1?categories=board,medium,gradeLevel,subject" + + print("inside content_form") + + board = tracker.get_slot('board') + grade = tracker.get_slot('grade') + medium = tracker.get_slot('medium') + + print('Grade -->', grade) + print('Medium -->', medium) + print('Board -->', board) + + channel_response = requests.get( + "https://staging.ntp.net.in/api/channel/v1/read/0126632859575746566") + # print("board_response-->", response.json()) + res_json = channel_response.json() + # print("type-->", type(response.json())) + # print("result-->",res_json['result']['channel']['frameworks']) + api_matching_board = self.get_board_api_mapped(board.lower()) + print("api_matching_board-->", api_matching_board) + channels = res_json['result']['channel']['frameworks'] + for channel in channels: + # print("x-->",x) + if api_matching_board in channel['identifier']: + board_identifier = channel['identifier'] + print("present in the list-->") + print("x[identifier]-->", channel['identifier']) + + if board_identifier: + print("inside if-->") + grade_mdium_url = "https://staging.ntp.net.in/api/framework/v1/read/" + \ + board_identifier + "?categories=board,medium,gradeLevel,subject" + print("grade_mdium_url-->", grade_mdium_url) + grade_medium_api_response = requests.get(grade_mdium_url) + res_framwork = grade_medium_api_response.json() + categories = res_framwork['result']['framework']['categories'] + # print("frameworks-->",categories) + + grade_to_compare = self.get_grade_mapped(grade.lower()) + print("grade_to_compare-->", grade_to_compare) + + medium_to_compare = self.get_medium_mapped(medium.lower()) + print("medium_to_compare-->", medium_to_compare) + + for category in categories: + if "medium" in category["code"]: + print("medium matched-->", category["code"]) + for term in category["terms"]: + if medium_to_compare in term["description"]: + print("medium matched") + break + # else : + # print("this medium is not available") + # dispatcher.utter_message(text = "this medium is not available for the mentioned board") + + # if "gradeLevel" in category["code"] : + # print("gradeLevel matched-->", category["code"]) + # for term in category["terms"]: + # if grade_to_compare in term["description"]: + # print("grade matched") + + # else : + # print("this grade is not available") + # dispatcher.utter_message(text = "this grade is not available for the mentioned medium") + + board_url = "?board=" + self.get_board_mapped(board.lower()) + medium_url = "&medium=" + self.get_medium_mapped(medium.lower()) + grade_url = "&gradeLevel=" + self.get_grade_mapped(grade.lower()) + url = base_url + board_url + medium_url + grade_url + + # returnObject = [{"type":"buttons","data":{"text":" Great! I understand that you are looking for content of "+ board + " board, class " + grade + ", " + medium + " medium .
" + # "Please visit: DIKSHA " + board + " Board
","intent":"greet","buttons":[]}}] + # print("returnObject-->",returnObject) + # dispatcher.utter_message(json_message = returnObject) + + print("Great! I understand that you are looking for content of " + board + " board, class " + grade + ", " + medium + " medium .
" + "Please visit: DIKSHA " + board + " Board") + + # elements = [{ + # "type": "buttons", + # "data": { + # "text": "Please visit DIKSHA CHANDIGARH
Select the Medium and Class to view relevant subject textbook on the board website.
", + # "intent": "greet", + # "buttons": [{ + # "text": "Go Back", + # "value": "99", + # }, + # { + # "text": "Main Menu", + # "value": "0", + # }] + # } + # }] + # elements = [{"type":"button", "data" : {"intent" : "greet", "buttons" : [] "text" : " Great! I understand that you are looking for content of "+ board + " board, class " + grade + ", " + medium + " medium .
" + # "Please visit: DIKSHA " + board + " Board
"} }] + + # dispatcher.utter_message(json_message=elements) + + + # dispatcher.utter_message( + # text = { + # "data": { + # "text": " Great! I understand that you are looking for content of "+ board + " board, class " + grade + ", " + medium + " medium .
" + # "Please visit: DIKSHA " + board + " Board
" + # } + # } + # ) + elements = [{ + "blocks": [{ + "intent": "greet", + "text": " Great! I understand that you are looking for content of " + board + " board, class " + grade + ", " + medium + " medium .
" + "Please visit: DIKSHA " + board + " Board
", + "type": "response" + }] + }] + dispatcher.utter_message(json_message=elements) + # elements = [{"type":"weather_action","entities":tracker.latest_message.get('entities'), "loc" : "abc", "intent" : "weather_action"}] + # dispatcher.utter_message(json_message=elements) + # dispatcher.utter_message(text=" Great! I understand that you are looking for content of " + board + " board, class " + grade + ", " + medium + " medium .
" + # "Please visit: DIKSHA " + board + " Board
") + else: + print("enter valid board") + return [SlotSet('board', board), SlotSet('grade', grade), SlotSet('medium', medium)] + + # def gererate_diksha_url(self): + + def get_board_api_mapped(self, board): + # print("get_board_mapped called") + data = '' + dirname = os.path.dirname(__file__) + filename = os.path.join(dirname, 'resources/boards_api.json') + with open(filename) as boards_api_values: + data = json.load(boards_api_values) + print("data in api mapping-->", data[board]) + return data[board] + + def get_board_mapped(self, board): + # print("get_board_mapped called") + data = '' + dirname = os.path.dirname(__file__) + filename = os.path.join(dirname, 'resources/boards.json') + with open(filename) as boards_values: + data = json.load(boards_values) + print("data in board-->", data[board]) + return data[board] + + def get_medium_mapped(self, medium): + # print("get_medium_mapped called") + data = '' + dirname = os.path.dirname(__file__) + filename = os.path.join(dirname, 'resources/mediums.json') + with open(filename) as mediums_values: + data = json.load(mediums_values) + # print("data in medium-->",data) + return data[medium] + + def get_grade_mapped(self, grade): + # print("get_grade_mapped called") + data = '' + dirname = os.path.dirname(__file__) + filename = os.path.join(dirname, 'resources/grades.json') + with open(filename) as grades_values: + data = json.load(grades_values) + # print("data in grade-->",data) + return data[grade] diff --git a/bot/config.yml b/bot/config.yml index bf250c4..6353b72 100644 --- a/bot/config.yml +++ b/bot/config.yml @@ -17,6 +17,7 @@ pipeline: # https://rasa.com/docs/rasa/core/policies/ policies: - name: MemoizationPolicy + - name: FormPolicy - name: KerasPolicy - name: MappingPolicy - name: FallbackPolicy diff --git a/bot/data/grades.txt b/bot/data/grades.txt index 572b563..f746772 100644 --- a/bot/data/grades.txt +++ b/bot/data/grades.txt @@ -6,6 +6,8 @@ five six seven eight +nine +ten first second third @@ -14,6 +16,8 @@ fifth sixth seventh eighth +ninth +tenth 1st 2nd 3rd @@ -22,6 +26,8 @@ eighth 6th 7th 8th +9th +10th 1 2 3 @@ -29,4 +35,6 @@ eighth 5 6 7 -8 \ No newline at end of file +8 +9 +10 \ No newline at end of file diff --git a/bot/data/nlu.md b/bot/data/nlu.md index e3a48d7..1faf6f2 100644 --- a/bot/data/nlu.md +++ b/bot/data/nlu.md @@ -126,13 +126,24 @@ ## intent:content_suggestions - I want to learn [CBSE](board) content +- I want to learn in [English](medium) medium - I'm a student from [Maharashtra](board) and want to learn from home - Do you have any content from [Karnataka](board) state board -- Show me class [one](grade) content from [Tamil Nadu](board) +- Show me class [one](grade) content from [TamilNadu](board) - Please show [second](grade) standard content - I want to do [maths](subject) revision - I want to learn [fourth](grade) standard [physics](subject) - +- I am a student of [karnataka](board) board and want to read [history](subject) books for [fifth](grade) standard +- can you suggest [mathematics](subject) books for [ninth](grade) class [cbse](board) board +- I want to learn [CBSE](board) board [second](grade) standard [physics](subject). +- I want to learn [CBSE](board) board [third](grade)standard in [English](medium). +- I am from [fourth](grade) standard +- I am from [tenth](grade) grade +- I want to learn [history](subject) +- I am from [Marathi](medium) medium +- I am in [third](grade) standard and I want to learn [maths](subject) +- I want to learn [science](subject) of [bihar](board) board + ## lookup:board data/boards.txt @@ -144,4 +155,3 @@ data/subjects.txt ## lookup:medium data/mediums.txt - diff --git a/bot/data/stories.md b/bot/data/stories.md index bda2995..418ff93 100644 --- a/bot/data/stories.md +++ b/bot/data/stories.md @@ -30,9 +30,9 @@ * content_customization - utter_content_customization -# content_suggestions + # language_support * language_support @@ -44,4 +44,12 @@ # worksheet * worksheet - - utter_worksheet \ No newline at end of file + - utter_worksheet + +# content_suggestions +* content_suggestions + - content_form + - form{"name": "board"} + - form{"name": "grade"} + - form{"name": "subject"} + - form{"name": "null"} diff --git a/bot/domain.yml b/bot/domain.yml index 1c5e2cf..dc4bd85 100644 --- a/bot/domain.yml +++ b/bot/domain.yml @@ -19,6 +19,20 @@ entities: - medium - subject +slots: + board: + type: unfeaturized + auto_fill: false + grade: + type: unfeaturized + auto_fill: false + subject: + type: unfeaturized + auto_fill: false + medium: + type: unfeaturized + auto_fill: false + actions: - utter_greet - utter_goodbye @@ -35,8 +49,15 @@ actions: - utter_worksheet - utter_content_suggestions - utter_get_started - -responses: +- utter_ask_valid_medium +- utter_ask_medium +- utter_ask_grade +- utter_ask_board +- action_courses +- utter_submit +- utter_response + +templates: utter_greet: - custom: blocks: @@ -108,7 +129,6 @@ responses: text: "We support English, Hindi, Kannada, Bengali, Marathi, Tamil, Telugu, Urdu languages." intent: "language_support" - utter_content_customization: - custom: blocks: @@ -116,9 +136,6 @@ responses: text: "Yes, you can customize the content for your domain. Any field/screen on DISKHA can be customized to suit organization needs." intent: "utter_content_customization" - utter_content_suggestions: - - text: "Sure, here are a few content for {board} {medium} {grade} {subject}" - utter_flag_reviewer: - custom: blocks: @@ -133,6 +150,64 @@ responses: text: "An author can be credited by following these steps. Log in to the diksha portal -> Select Workspace -> Select Create -> click the Course tile. -> Click Edit Details to enter/ modify the course details -> Enter Creators -> Enter Contributors details -> Enter Original Author details -> Click Save to save the details" intent: "author_credit" + utter_content_suggestions: + - custom: + blocks: + - type: "response" + text: "Sure, here are a few content for {board} {medium} {grade} {subject}" + intent: "content_suggestions" + + utter_ask_valid_medium: + - custom: + blocks: + - type: "response" + text: "Please enter the valid medium" + intent: "content_suggestions" + + utter_ask_board: + - custom: + blocks: + - type: "response" + text: "Please select the valid board" + intent: "which_board" + + utter_ask_grade: + - custom: + blocks: + - type: "response" + text: "Which standard content would you like to browse?" + intent: "which_grade" + + utter_ask_subject: + - custom: + blocks: + - type: "response" + text: "Can you name the subject you are interested in?" + intent: "which_subject" + + utter_submit: + - custom: + blocks: + - type: "response" + text: "subject: {subject}, board: {board}, grade: {grade}" + intent: "submit" + + utter_response: + - custom: + blocks: + - type: "response" + text: "subject: {subject}, board: {board}, grade: {grade}" + intent: "greet " + + utter_ask_medium: + - custom: + blocks: + - type: "response" + text: "Please enter the valid medium" + intent: "content_suggestions" + +forms: + - content_form session_config: session_expiration_time: 60 diff --git a/bot/resources/boards.json b/bot/resources/boards.json new file mode 100644 index 0000000..3d7afb6 --- /dev/null +++ b/bot/resources/boards.json @@ -0,0 +1,57 @@ +{ + "cbse": "CBSE", + "tamil nadu": "State (Tamil Nadu)", + "tamilnadu": "State (Tamil Nadu)", + "tn": "State (Tamil Nadu)", + "karnataka": "State (Karnataka)", + "ka": "State (Karnataka)", + "gujarat": "State (Gujarat)", + "gj": "State (Gujarat)", + "uttar pradesh": "State (Uttar Pradesh)", + "uttarpradesh": "State (Uttar Pradesh)", + "up": "State (Uttar Pradesh)", + "punjab": "State (Punjab)", + "pb": "State (Punjab)", + "rajasthan": "State (Rajasthan)", + "rj": "State (Rajasthan)", + "manipur": "State (Manipur)", + "mn": "State (Manipur)", + "chhattisgarh": "State (Chhattisgarh)", + "cg": "State (Chhattisgarh)", + "maharashtra": "State (Maharashtra)", + "mh": "State (Maharashtra)", + "mitra": "State (Maharashtra)", + "bihar": "State (Bihar)", + "br": "State (Bihar)", + "odisha": "State (Odisha)", + "od": "State (Odisha)", + "orissa":"State (Odisha)", + "assam": "State (Assam)", + "as": "State (Assam)", + "madhya pradesh" : "State (Madhya Pradesh)", + "madhyapradesh" : "State (Madhya Pradesh)", + "mp" : "State (Madhya Pradesh)", + "haryana": "State (Haryana)", + "hr": "State (Haryana)", + "nagaland": "State (Nagaland)", + "ng": "State (Nagaland)", + "goa": "State (Goa)", + "ga": "State (Goa)", + "telangana": "State (Telagana)", + "ts": "State (Telagana)", + "andhra pradesh": "State (Andhra Pradesh)", + "andhrapradesh": "State (Andhra Pradesh)", + "ap": "State (Andhra Pradesh)", + "apex": "State (Andhra Pradesh)", + "meghalaya": "State (Meghalaya)", + "mg": "State (Meghalaya)", + "jharkhand": "State (Jharkhand)", + "jh": "State (Jharkhand)", + "sikkim": "State (Sikkim)", + "sk": "State (Sikkim)", + "chandigarh": "State (Chandigarh)", + "ch": "State (Chandigarh)", + "igot-health": "iGOT-Health", + "igot": "iGOT-Health", + "igot health": "iGOT-Health" +} \ No newline at end of file diff --git a/bot/resources/boards_api.json b/bot/resources/boards_api.json new file mode 100644 index 0000000..f87f3bb --- /dev/null +++ b/bot/resources/boards_api.json @@ -0,0 +1,58 @@ +{ + "maharashtra": "mh_k-12_15", + "mh": "mh_k-12_15", + "mitra": "mh_k-12_15", + "uttar pradesh": "up_k-12_5", + "uttarpradesh": "up_k-12_5", + "up": "up_k-12_5", + "tamil nadu": "tn_k-12_6", + "tamilnadu": "tn_k-12_6", + "tn": "tn_k-12_6", + "nagaland": "nl_k-12", + "ng": "nl_k-12", + "rajasthan": "rj_k-12_1", + "rj": "rj_k-12_1", + "cbse": "CBSE", + "karnataka": "ka_k-12_1", + "ka": "ka_k-12_1", + "gujarat": "State (Gujarat)", + "gj": "State (Gujarat)", + "punjab": "State (Punjab)", + "pb": "State (Punjab)", + "manipur": "State (Manipur)", + "mn": "State (Manipur)", + "chhattisgarh": "State (Chhattisgarh)", + "cg": "State (Chhattisgarh)", + "bihar": "State (Bihar)", + "br": "State (Bihar)", + "odisha": "State (Odisha)", + "od": "State (Odisha)", + "orissa":"State (Odisha)", + "assam": "State (Assam)", + "as": "State (Assam)", + "madhya pradesh" : "State (Madhya Pradesh)", + "madhyapradesh" : "State (Madhya Pradesh)", + "mp" : "State (Madhya Pradesh)", + "haryana": "State (Haryana)", + "hr": "State (Haryana)", + + "goa": "State (Goa)", + "ga": "State (Goa)", + "telangana": "State (Telagana)", + "ts": "State (Telagana)", + "andhra pradesh": "State (Andhra Pradesh)", + "andhrapradesh": "State (Andhra Pradesh)", + "ap": "State (Andhra Pradesh)", + "apex": "State (Andhra Pradesh)", + "meghalaya": "State (Meghalaya)", + "mg": "State (Meghalaya)", + "jharkhand": "State (Jharkhand)", + "jh": "State (Jharkhand)", + "sikkim": "State (Sikkim)", + "sk": "State (Sikkim)", + "chandigarh": "State (Chandigarh)", + "ch": "State (Chandigarh)", + "igot-health": "iGOT-Health", + "igot": "iGOT-Health", + "igot health": "iGOT-Health" +} \ No newline at end of file diff --git a/bot/resources/grades.json b/bot/resources/grades.json new file mode 100644 index 0000000..b5c1b65 --- /dev/null +++ b/bot/resources/grades.json @@ -0,0 +1,66 @@ +{ + "one": "Class 1", + "first":"Class 1", + "1st":"Class 1", + "1":"Class 1", + "two":"Class 2", + "second":"Class 2", + "2nd":"Class 2", + "2":"Class 2", + "three":"Class 3", + "third":"Class 3", + "3rd":"Class 3", + "3":"Class 3", + "four":"Class 4", + "fourth":"Class 4", + "4th":"Class 4", + "4":"Class 4", + "five":"Class 5", + "Fifth":"Class 5", + "5th":"Class 5", + "5":"Class 5", + "six":"Class 6", + "sixth":"Class 6", + "6th":"Class 6", + "6":"Class 6", + "seven":"Class 7", + "seventh":"Class 7", + "7th":"Class 7", + "7":"Class 7", + "eight":"Class 8", + "eighth":"Class 8", + "8th":"Class 8", + "8":"Class 8", + "nine":"Class 9", + "nineth":"Class 9", + "9th":"Class 9", + "9":"Class 9", + "ten":"Class 10", + "tenth":"Class 10", + "10th":"Class 10", + "10":"Class 10", + "eleven":"Class 11", + "eleventh":"Class 11", + "11th":"Class 11", + "11":"Class 11", + "twelve":"Class 12", + "twelveth":"Class 12", + "12th":"Class 12", + "12":"Class 12", + "doctors":"Doctors", + "nurses":"Nurses", + "nolunteers":"Volunteers", + "hygiene workers":"Hygiene Workers", + "hygieneworker":"Hygiene Workers", + "police":"Police", + "civil defence officials":"Civil Defence Officials", + "defence officials":"Civil Defence Officials", + "civil defence":"Civil Defence Officials", + "anms":"ANMs", + "other state officials":"Other State Officials", + "state officials":"Civil Defence Officials", + "paramedics":"Paramedics", + "other technicians":"Other Technicians", + "ayush doctors":"Ayush Doctors", + "ayush":"Ayush Doctors" + } \ No newline at end of file diff --git a/bot/resources/mediums.json b/bot/resources/mediums.json new file mode 100644 index 0000000..15959bd --- /dev/null +++ b/bot/resources/mediums.json @@ -0,0 +1,26 @@ +{ + "english":"English", + "assamese" : "Assamese", + "hindi":"Hindi", + "sanskrit":"Sanskrit", + "marathi": "Marathi", + "urdu":"Urdu", + "telugu":"Telugu", + "bengali":"Bengali", + "bodo":"Bodo", + "gujarati":"Gujarati", + "malayalam":"Malayalam", + "kannada":"Kannada", + "tamil":"Tamil", + "arabic":"Arabic", + "mizo":"Mizo", + "odia":"Odia", + "punjabi":"Punjabi", + "bhojpuri":"Bhojpuri", + "brij bhasha":"Brij Bhasha", + "brij":"Brij Bhasha", + "awadhi":"Awadhi", + "Bundelkhandi":"Bundelkhandi", + "konkani":"Konkani", + "sign language":"Sign Language" + } \ No newline at end of file diff --git a/router/api/rasa.core/botwebhook.js b/router/api/rasa.core/botwebhook.js index 6f7194c..f835d2e 100644 --- a/router/api/rasa.core/botwebhook.js +++ b/router/api/rasa.core/botwebhook.js @@ -7,8 +7,12 @@ function processResponse(res, cb) { let quick_replies = [] let intent = '' let resp = res.data.map((item) => { - LOG.info('item@processResponse@botwebhook:', JSON.stringify(item)) + LOG.info('item@processResponse@botwebhook:') + LOG.info(JSON.stringify(item)) + LOG.info("item-->",item) + LOG.info("item.text",item.text) if (item.text) { + LOG.info('inside item.text') if (item.text.split('-----').length > 1) { intent = item.text.split('-----')[1] item.text = item.text.split('-----')[0] @@ -25,7 +29,9 @@ function processResponse(res, cb) { "intent": intent } } else if (item.custom) { + console.log("inside item.custom") if (item.custom.blocks) { + console.log("inside item.custom.blocks") quick_replies = item.custom text = item.text type = '' @@ -56,13 +62,27 @@ function processResponse(res, cb) { } } else { + console.log("inside else item.custom") quick_replies = item.custom + + console.log("item.custom[0]-->",item.custom[0]) + console.log("item.custom[0].blocks[0].text-->",item.custom[0].blocks[0].text) + text = item.text type = '' entities = [] if (item.custom[0].intent) { intent = item.custom[0].intent } + if (item.custom[0].blocks[0] && item.custom[0].blocks[0].text) { + console.log("inside item.custom[0].blocks[0]") + text = { + "data": { + "text": item.custom[0].blocks[0].text + } + } + } + if (item.custom[0].text) { text = item.custom[0].text } @@ -82,6 +102,7 @@ function processResponse(res, cb) { } } else { + console.log("inside else ") if (item.button) { quick_replies.push(item.button) } diff --git a/router/appRest.js b/router/appRest.js index 2c647fc..87be4bb 100644 --- a/router/appRest.js +++ b/router/appRest.js @@ -62,12 +62,14 @@ function handler(req, res, channel) { // all non numeric user messages go to bot if (isNaN(message)) { ///Bot interaction flow + // add userid RasaCoreController.processUserData(data, deviceId, (err, resp) => { var response = ''; if (err) { sendChannelResponse(deviceId, res, 'SORRY', channel) } else { var responses = resp.res; + console.log("responses-->",responses) if (responses && responses[0].text) { response = responses[0].text; telemetryData = createInteractionData(responses[0], data.customData, true); @@ -92,25 +94,31 @@ function handler(req, res, channel) { currentFlowStep = possibleFlow; responseKey = chatflowConfig[currentFlowStep].messageKey // TODO : Don't call function inside each if/else if it should be called once. + //log for known telemetryData = createInteractionData({ currentStep: currentFlowStep, responseKey: responseKey }, data.customData, false) } else if (message === '0') { currentFlowStep = 'step1' responseKey = chatflowConfig[currentFlowStep].messageKey // TODO : Don't call function inside each if/else if it should be called once. + //log for known telemetryData = createInteractionData({ currentStep: currentFlowStep, responseKey: responseKey }, data.customData, false) } else if (message === '99') { if (currentFlowStep.lastIndexOf("_") > 0) { currentFlowStep = currentFlowStep.substring(0, currentFlowStep.lastIndexOf("_")) responseKey = chatflowConfig[currentFlowStep].messageKey // TODO : Don't call function inside each if/else if it should be called once. + //log for known - flag set telemetryData = createInteractionData({ currentStep: currentFlowStep, responseKey: responseKey }, data.customData, false) } } else { responseKey = getErrorMessageForInvalidInput(currentFlowStep, chatflowConfig) // TODO : Don't call function inside each if/else if it should be called once. + //log for unknown - flag set telemetryData = createInteractionData({ currentStep: currentFlowStep + '_UNKNOWN_OPTION' }, data.customData, false) } redisSessionData['currentFlowStep'] = currentFlowStep; + // botresponse = currentFlowStep + // log method setRedisKeyValue(deviceId, redisSessionData); telemetry.logInteraction(telemetryData) sendChannelResponse(res, responseKey, channel); diff --git a/router/config/chatflow.js b/router/config/chatflow.js index 8ef471d..677f691 100644 --- a/router/config/chatflow.js +++ b/router/config/chatflow.js @@ -1,44 +1,240 @@ var chatflow = { -}; - -var teacher = { step1: { - messageKey: "START_TEACHER", - responseVariable: "userType", + messageKey: "START", + responseVariable: "userIntent" + }, + step1_error: { + messageKey: "UNKNOWN_OPTION", + responseVariable: "" }, step1_1: { - messageKey: "CHOOSE_BOARD", - responseVariabl: "userLevel", + messageKey: "CHOOSE_DIGITAL_CONTENT", + responseVariable: "userBoard" }, step1_1_1: { - messageKey: "EDUCATION_LEVEL", - responseVariabl: "userBoard", + messageKey: "CHOOSE_BOARD", + responseVariable: "userBoard" }, - step1_wrong_input: { - messageKey: "SORRY", + step1_1_error: { + messageKey: "WRONG_INPUT_AT_FIRST_LEVEL", responseVariable: "" - } -}; -var student = { - step1: { - messageKey: "START_STUDENT", - responseVariable: "userType", }, - step1_1: { - messageKey: "CHOOSE_BOARD", - responseVariabl: "userLevel", + step1_1_1_1: { + messageKey: "CBSE_MESSAGE", + responseVariable: "" }, - step1_1_1: { - messageKey: "EDUCATION_LEVEL", - responseVariabl: "userBoard", + step1_1_1_2: { + messageKey: "CHOOSE_STATE_BOARD", + responseVariable: "stateBoard" + }, + step1_1_1_2_error: { + messageKey: "WRONG_INPUT_AT_SECOND_LEVEL", + responseVariable: "" + }, + step1_1_1_2_1: { + messageKey: "TN_BOARD", + responseVariable: "" + }, + step1_1_1_2_2: { + messageKey: "KA_BOARD", + responseVariable: "" + }, + step1_1_1_2_3: { + messageKey: "GJ_BOARD", + responseVariable: "" + }, + step1_1_1_2_4: { + messageKey: "UP_BOARD", + responseVariable: "" + }, + step1_1_1_2_5: { + messageKey: "PB_BOARD", + responseVariable: "" + }, + step1_1_1_2_6: { + messageKey: "RJ_BOARD", + responseVariable: "" + }, + step1_1_1_2_7: { + messageKey: "MN_BOARD", + responseVariable: "" + }, + step1_1_1_2_8: { + messageKey: "CG_BOARD", + responseVariable: "" + }, + step1_1_1_2_9: { + messageKey: "MITRA_BOARD", + responseVariable: "" + }, + step1_1_1_2_10: { + messageKey: "BR_BOARD", + responseVariable: "" + }, + step1_1_1_2_11: { + messageKey: "OD_BOARD", + responseVariable: "" + }, + step1_1_1_2_12: { + messageKey: "AS_BOARD", + responseVariable: "" + }, + step1_1_1_2_13: { + messageKey: "MP_BOARD", + responseVariable: "" + }, + step1_1_1_2_14: { + messageKey: "HR_BOARD", + responseVariable: "" + }, + step1_1_1_2_15: { + messageKey: "NL_BOARD", + responseVariable: "" + }, + step1_1_1_2_16: { + messageKey: "GA_BOARD", + responseVariable: "" + }, + step1_1_1_2_17: { + messageKey: "TS_BOARD", + responseVariable: "" + }, + step1_1_1_2_18: { + messageKey: "APEKX_BOARD", + responseVariable: "" + }, + step1_1_1_2_19: { + messageKey: "ML_BOARD", + responseVariable: "" + }, + step1_1_1_2_20: { + messageKey: "NCERT_BOARD", + responseVariable: "" + }, + step1_1_1_2_21: { + messageKey: "JH_BOARD", + responseVariable: "" + }, + step1_1_1_2_22: { + messageKey: "SK_BOARD", + responseVariable: "" + }, + step1_1_1_2_23: { + messageKey: "CH_BOARD", + responseVariable: "" + }, + + step1_1_2: { + messageKey: "WEEKLY_CRITICAL_THINKING", + responseVariable: "" + }, + step1_1_2_error: { + messageKey: "WRONG_INPUT_AT_FIRST_LEVEL", + responseVariable: "" + }, + step1_2: { + messageKey: "TRAINING", + responseVariable: "" + }, + step1_2_error: { + messageKey: "WRONG_INPUT_AT_FIRST_LEVEL", + responseVariable: "" + }, + step1_2_1: { + messageKey: "CHOOSE_STATE_TRAINING_BOARD", + responseVariable: "" + }, step1_2_1_1: { + messageKey: "TRAINING_CBSE_BOARD", + responseVariable: "" + }, + step1_2_1_2: { + messageKey: "TRAINING_UP_BOARD", + responseVariable: "" + }, + step1_2_1_3: { + messageKey: "TRAINING_MP_BOARD", + responseVariable: "" + }, + step1_2_1_4: { + messageKey: "TRAINING_GJ_BOARD", + responseVariable: "" + }, + step1_2_1_5: { + messageKey: "TRAINING_RJ_BOARD", + responseVariable: "" + }, + step1_2_1_6: { + messageKey: "TRAINING_HARYANA_BOARD", + responseVariable: "" + }, + step1_2_1_7: { + messageKey: "TRAINING_OTHERS_BOARD", + responseVariable: "" + }, + step1_2_1_1_error: { + messageKey: "WRONG_INPUT_AT_FIRST_LEVEL", + responseVariable: "" + }, + step1_2_2: { + messageKey: "CHOOSE_IGOT_TRAINING_OPTION", + responseVariable: "" + }, + step1_2_2_error: { + messageKey: "WRONG_INPUT_AT_FIRST_LEVEL", + responseVariable: "" + }, + step1_2_2_1: { + messageKey: "IGOT_TRAINING", + responseVariable: "" + }, + step1_2_2_2: { + messageKey: "CERTIFICATE_ISSUE", + responseVariable: "" + }, + step1_2_2_error: { + messageKey: "WRONG_INPUT_AT_FIRST_LEVEL", + responseVariable: "" + }, + step1_2_error: { + messageKey: "WRONG_INPUT_AT_FIRST_LEVEL", + responseVariable: "" + }, + step1_3: { + messageKey: "PLAYSTORE", + responseVariable: "" + }, + step1_4: { + messageKey: "CONTRIBUTE_CONTENT", + responseVariable: "" + }, + step1_5: { + messageKey: "OTHER_OPTIONS", + responseVariable: "other_options" + }, + step1_5_1: { + messageKey: "SCAN_QRCODE", + responseVariable: "" + }, + step1_5_2: { + messageKey: "UNABLE_LOGIN", + responseVariable: "" + }, + step1_5_3: { + messageKey: "FORGOT_PASSWORD", + responseVariable: "" + }, + step1_5_4: { + messageKey: "OTHERS", + responseVariable: "" + }, + step1_5_error: { + messageKey: "WRONG_INPUT_AT_SECOND_LEVEL", + responseVariable: "" }, step1_wrong_input: { - messageKey: "SORRY", + messageKey: "UNKNOWN_OPTION", responseVariable: "" } }; - -module.exports.chatflow = student; -module.exports.teacher = teacher -module.exports.student = student; \ No newline at end of file +module.exports.chatflow = chatflow; \ No newline at end of file diff --git a/router/config/literals.js b/router/config/literals.js index 54cf89e..5c398dc 100644 --- a/router/config/literals.js +++ b/router/config/literals.js @@ -1,15 +1,1301 @@ -var message = {} +var message = {} +message.START = { + "type": "button", + "data": { + "text": " Hello, I am Tara!
I am your DIKSHA guide
Please select your preference from the options I provide or type your query directly.", + "buttons": [ + { + "text": "Digital content", + "value": "1" + }, + { + "text": "Courses", + "value": "2" + }, + { + "text": "DIKSHA mobile app", + "value": "3", + }, + { + "text": "Content contribution", + "value": "4", + }, + { + "text": "Other DIKSHA queries", + "value": "5", + } + ] + } +} -message.START_STUDENT = "Hello, Kindly choose a number against the role which you identify with.\n 1 for Student \n 2 for Parent. \nAt any point of time Type 0 for menu" -message.START_TEACHER = "Hello, Kindly choose a number against the role which you identify with.\n 1 for Teacher \n 2 for Parent. \nAt any point of time Type 0 for menu" +message.CHOOSE_DIGITAL_CONTENT = { -message.WELCOME = "Hello, Kindly choose a number against the role which you identify with.\n 1 for Student \n 2 for Teacher \n 3 for Parent. \nAt any point of time Type 0 for menu" + "type": "button", + "data": { + "text": " What content would you like to explore?", + "buttons": [ + { + "text": "Textbook videos & practice questions", + "value": 1, + }, + { + "text": "Critical thinking questions", + "value": 2, + }, + { + "text": "Main Menu", + "value": "0", + } + ] + } +} -message.LINK = "Please follow this link to find relevant material: https://diksha.gov.in/" -message.BOARD_NOT_HANDLED = "please choose from CBSE or State Board, other bords are not handled as of yet. 1. CBSE \n 2. State Board. \nType 0 for menu." -message.CHOOSE_STATE = "Thanks, send corresponding number if you belong to these states. \n 1 for Andhra Pradesh \n 2 for Karnataka \n 3 for Tamil Nadu" -message.EDUCATION_LEVEL = "Thanks, send 1 if you are a School Student or 2 if you are pursuing Higher Education" -message.SORRY = "Sorry, can you come again please?" -message.CHOOSE_BOARD = "Thanks, send corresponding number if you belong to these boards.\n 1. CBSE \n 2. State Board \n 3. NIOS \n 4. Others" +message.CHOOSE_BOARD = +{ + "type": "button", + "data": { + "text": " Tell me which board you belong to", + "buttons": [ + { + "text": "CBSE", + "value": 1, + }, + { + "text": "State Board", + "value": 2, + }, + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + } + ] + } +} -module.exports.message = message; \ No newline at end of file +message.CBSE_MESSAGE = +{ + "type": "button", + "data": { + "text": "Please visit: DIKSHA CBSE
Select the Medium and Class to view relevant subject textbook on the board website.
", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.CHOOSE_STATE_BOARD = +{ + "type": "button", + "data": { + "text": " Which state board do you belong to? ", + "buttons": [{ + "text": "Tamilnadu", + "value": 1, + }, + { + "text": "Karnataka", + "value": 2, + }, + { + "text": "Gujarat", + "value": 3, + }, + { + "text": "UttarPradesh", + "value": 4, + }, + { + "text": "Punjab", + "value": 5, + }, + { + "text": "Rajasthan", + "value": 6, + }, + { + "text": "Manipur", + "value": 7, + }, + { + "text": "Chhattisgarh", + "value": 8, + }, + { + "text": "Maharashtra", + "value": 9, + }, + { + "text": "Bihar", + "value": 10, + }, + { + "text": "Odisha", + "value": 11, + }, + { + "text": "Assam", + "value": 12, + }, + { + "text": "Madhya Pradesh", + "value": 13, + }, + { + "text": "Haryana", + "value": 14, + }, + { + "text": "Nagaland", + "value": 15, + }, + { + "text": "Goa", + "value": 16, + }, + { + "text": "Telangana", + "value": 17, + }, + { + "text": "Andhra Pradesh", + "value": 18, + }, + { + "text": "Meghalaya", + "value": 19, + }, + { + "text": "NCERT", + "value": 20, + }, + { + "text": "Jharkhand", + "value": 21, + }, + { + "text": "Sikkim", + "value": 22, + }, + { + "text": "Chandigarh", + "value": 23, + }, + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TN_BOARD = +{ + "type": "button", + "data": { + "text": " Please visit DIKSHA TAMILNADU
Select the Medium and Class to view relevant subject textbook on the board website.
", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.KA_BOARD = + +{ + "type": "button", + "data": { + "text": " Please visit DIKSHA KARNATAKA
Select the Medium and Class to view relevant subject textbook on the board website.
", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.GJ_BOARD = +{ + "type": "button", + "data": { + "text": " Please visit DIKSHA GUJARAT
Select the Medium and Class to view relevant subject textbook on the board website.
", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.UP_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA UTTARPRADESH
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.PB_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA UTTARPRADESH
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.RJ_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA RAJASTHAN
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.MN_BOARD = +{ + "text": " Please visit DIKSHA MANIPUR
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "type": "buttons", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] +} + +message.CG_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA CHHATTISGARH
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.MITRA_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA MAHARASHTRA
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.BR_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA BIHAR
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.OD_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA ODISHA
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.AS_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA ASSAM
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.MP_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA MADHYAPRADESH
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.HR_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA HARYANA
Select the Medium and Class to view relevant subject textbook on the board website.


** Press 99 to go back to choose another board or press 0 to go to Main Menu.", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.NL_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA NAGALAND
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.GA_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA GOA
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TS_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA TELANGANA
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.APEKX_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA ANDHRAPRADESH
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.ML_BOARD = +{ + "type": "buttons", + "data": { + "text": " Please visit DIKSHA MEGHALAYA
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.NCERT_BOARD = +{ + "type": "buttons", + "data": { + "text": "Please visit DIKSHA NCERT
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.JH_BOARD = +{ + "type": "buttons", + "data": { + "text": "Please visit DIKSHA JHARKHAND
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.SK_BOARD = +{ + "type": "buttons", + "data": { + "text": "Please visit DIKSHA SIKKIM
Select the Medium and Class to view relevant subject textbook on the board website.DIKSHA CHANDIGARH
Select the Medium and Class to view relevant subject textbook on the board website.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.WEEKLY_CRITICAL_THINKING = +{ + "type": "button", + "data": { + "text": " Please visit: Critical thinking questions

Select the Subject to view relevant content on the page", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TRAINING = +{ + "type": "button", + "data": { + "text": " Select the course you would like to do
", + "buttons": [{ + "text": "State Courses", + "value": 1, + }, + { + "text": "IGOT Courses", + "value": 2, + }, + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.CHOOSE_STATE_TRAINING_BOARD = +{ + "type": "button", + "data": { + "text": "Which state board do you belong to?
", + "buttons": [{ + "text": "CBSE", + "value": 1, + }, + { + "text": "Uttar Pradesh", + "value": 2, + }, + { + "text": "Madhya Pradesh", + "value": 3, + }, + { + "text": "Gujarat", + "value": 4, + }, + { + "text": "Rajasthan", + "value": 5, + }, + { + "text": "Haryana", + "value": 6, + }, + { + "text": "Others", + "value": 7, + }, + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TRAINING_CBSE_BOARD = +{ + + "intent": "greet", + "type": "buttons", + "data": { + "text": "Please visit:DIKSHA CBSE Course
Select the Topic, Medium, Class and Subject to view relevant course on the website.
", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TRAINING_UP_BOARD = +{ + + "intent": "greet", + "type": "buttons", + "data": { + "text": "Please visit:DIKSHA UP Course ", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TRAINING_MP_BOARD = +{ + + "intent": "greet", + "type": "buttons", + "data": { + "text": "Please visit:DIKSHA MP Course
Select the Topic, Medium, Class and Subject to view relevant course on the website.
", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TRAINING_GJ_BOARD = +{ + + "intent": "greet", + "type": "buttons", + "data": { + "text": "Please visit: DIKSHA GJ Course
Select the Topic, Medium, Class and Subject to view relevant course on the website.
", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TRAINING_RJ_BOARD = +{ + + "intent": "greet", + "type": "buttons", + "data": { + "text": "Please visit: DIKSHA RJ Course
Select the Topic, Medium, Class and Subject to view relevant course on the website.
", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TRAINING_HARYANA_BOARD = +{ + + "intent": "greet", + "type": "buttons", + "data": { + "text": "Please visit: DIKSHA HARYANA Course
Select the Topic, Medium, Class and Subject to view relevant course on the website.
", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.TRAINING_OTHERS_BOARD = +{ + + "intent": "greet", + "type": "buttons", + "data": { + "text": "I understand you want to take a state training.
Please visit and select the Topic, Medium, Class and Subject to view relevant training.
DIKSHA State Course
", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.CHOOSE_IGOT_TRAINING_OPTION = +{ + "type": "button", + "data": { + "text": "Select what you are looking for
", + "buttons": [{ + "text": "Take IGOT course", + "value": 1, + }, + { + "text": "Issues with course/certificate", + "value": 2, + }, + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + } + ] + } +} + +message.IGOT_TRAINING = +{ + "type": "button", + "data": { + "text": "Please visit:IGOT Courses
Select the role to view relevant course on the website.
", + "buttons": [ + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.CERTIFICATE_ISSUE = +{ + "type": "button", + "data": { + "text": " Please write your concern to support@i-got.freshdesk.com
", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.PLAYSTORE = +{ + "type": "buttons", + "data": { + "text": " Please visit: DIKSHA mobile app

Step 1. Download the DIKSHA mobile app from the link given above
Step 2. Install the DIKSHA app
Step 3. Follow the instructions provided in the app

You are good to go!
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.CONTRIBUTE_CONTENT = +{ + "type": "buttons", + "data": { + "text": " Please visit: VIDYADAAN
Use a desktop or laptop to start contributing content to be used by the nation.
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.OTHER_OPTIONS = +{ + "type": "buttons", + "data": { + "text": " Please select from the options : ", + "intent": "greet", + "buttons": [{ + "text": "Scan QR code", + "value": 1, + }, + { + "text": "Login issues", + "value": 2, + }, + { + "text": "Reset password", + "value": 3, + }, + { + "text": "Other queries", + "value": 4, + }, + { + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + } + ] + } +} + +message.SCAN_QRCODE = +{ + "type": "buttons", + "data": { + "text": "Please visit: Scan QR Code
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.UNABLE_LOGIN = +{ + "type": "buttons", + "data": { + "text": " Please visit: Login issues​
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.FORGOT_PASSWORD = +{ + "type": "buttons", + "data": { + "text": "Please visit: Reset password
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.OTHERS = +{ + "type": "buttons", + "data": { + "text": "Please visit: Other issues
", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.UNKNOWN_OPTION = +{ + "type": "buttons", + "data": { + "text": "Sorry, I do not understand what you’re asking.", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.SORRY = +{ + "type": "buttons", + "data": { + "text": "Sorry, can you come again please?", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.WRONG_INPUT_AT_FIRST_LEVEL = +{ + "type": "buttons", + "data": { + "text": "Sorry, I do not understand what you’re asking.", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + +message.WRONG_INPUT_AT_SECOND_LEVEL = +{ + "type": "buttons", + "data": { + "text": "Sorry, I do not understand what you're asking. Go to Main Menu or type your query directly, so I can help you better.", + "intent": "greet", + "buttons": [{ + "text": "Go Back", + "value": "99", + }, + { + "text": "Main Menu", + "value": "0", + }] + } +} + + +message.START_whatsapp = +{ + "text": "Hi, I’m TARA, your DIKSHA assistant. How may I help you today? \n Select from one of the following options. Send the number corresponding to your choice \n 1- To find and play content \n 2- To download/update the DIKSHA mobile app \n 3- Other Queries", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.CHOOSE_BOARD_whatsapp = +{ + "text": "Tell me which of the following board you belong to, so that I can assist you better. Send the number corresponding to the board. \n1- CBSE \n2- State Board ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.CBSE_MESSAGE_whatsapp = +{ + "text": "Please visit 'https://diksha.gov.in/CBSE/explore to access eResources, videos, DFs and practice sheets from the topics in your syllabus. Happy learning!\n\n Press 99 to go back to the previous menu or 0 to the main menu ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.CHOOSE_STATE_BOARD_whatsapp = +{ + "text": "Which of the following state boards you belong to? Send the number corresponding to your choice \n1- Tamil Nadu \n2- Karnataka \n3- Gujarat \n4- Uttar Pradesh", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.TN_BOARD_whatsapp = +{ + "text": "Please visit https://diksha.gov.in/tn/explore Select the Medium and Class to view relevant subject textbook\n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.KA_BOARD_whatsapp = +{ + "text": "Please visit https://diksha.gov.in/ka/explore Select the Medium and Class to view relevant subject textbook\n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.GJ_BOARD_whatsapp = +{ + "text": "Please visit https://diksha.gov.in/gj/explore Select the Medium and Class to view relevant subject textbook\n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.UP_BOARD_whatsapp = +{ + "text": "Please visit https://diksha.gov.in/up/explore Select the Medium and Class to view relevant subject textbook\n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.PLAYSTORE_whatsapp = +{ + "text": "Please visit https://play.google.com/store/apps/details?id=in.gov.diksha.app&hl=en_IN​. \n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.OTHER_OPTIONS_whatsapp = +{ + "text": "Please select from the following options. Send the number corresponding to your choice - \n1- How to scan using qr code? \n2- Not able to Login \n3- Others", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.SCAN_QRCODE_whatsapp = +{ + "text": "Please visit: https://diksha.gov.in/help/getting-started/diksha-mobile-app/understanding-qr-code.html. \n\nPress 99 to go back to the previous menu or 0 to the main menu. ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.UNABLE_LOGIN_whatsapp = +{ + "text": "Please visit: https://diksha.gov.in/help/getting-started/sign-in/index.html. \n\nPress 99 to go back to the previous menu or 0 to the main menu ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.OTHERS_whatsapp = +{ + "text": "Please visit: https://diksha.gov.in/help/getting-started/explore-diksha/index.html. \n\nPress 99 to go back to the previous menu or 0 to the main menu. ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.UNKNOWN_OPTION_whatsapp = +{ + "text": "Sorry, I do not understand what you’re asking. Please choose from the following options or press 0 for the main menu, so I can help you better", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.SORRY_whatsapp = +{ + "text": "Sorry, can you come again please?", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.START_telegram = +{ + "text": "Hi, I’m TARA, your DIKSHA assistant. How may I help you today? \n Select from one of the following options. Send the number corresponding to your choice \n 1- To find and play content \n 2- To download/update the DIKSHA mobile app \n 3- Other Queries", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.CHOOSE_BOARD_telegram = +{ + "text": "Tell me which of the following board you belong to, so that I can assist you better. Send the number corresponding to the board.: \n1- CBSE \n2- State Board ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.CBSE_MESSAGE_telegram = +{ + "text": "Please visit 'https://diksha.gov.in/CBSE/explore to access eResources, videos, DFs and practice sheets from the topics in your syllabus. Happy learning!\n\n Press 99 to go back to the previous menu or 0 to the main menu ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.CHOOSE_STATE_BOARD_telegram = +{ + "text": "Which of the following state boards you belong to? Send the number corresponding to your choice \n1- Tamil Nadu \n2- Karnataka \n3- Gujarat \n4- Uttar Pradesh", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.TN_BOARD_telegram = +{ + "text": "Please visit https://diksha.gov.in/tn/explore Select the Medium and Class to view relevant subject textbook\n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} +message.KA_BOARD_telegram = +{ + "text": "Please visit https://diksha.gov.in/ka/explore Select the Medium and Class to view relevant subject textbook\n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.GJ_BOARD_telegram = +{ + "text": "Please visit https://diksha.gov.in/gj/explore Select the Medium and Class to view relevant subject textbook\n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.UP_BOARD_telegram = +{ + "text": "Please visit https://diksha.gov.in/up/explore Select the Medium and Class to view relevant subject textbook\n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.PLAYSTORE_telegram = +{ + "text": "Please visit https://play.google.com/store/apps/details?id=in.gov.diksha.app&hl=en_IN. \n\nPress 99 to go back to the previous menu or 0 to the main menu.", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.OTHER_OPTIONS_telegram = +{ + "text": "Please select from the following options- \n1- How to scan using qr code? \n2- Not able to Login \n3- Others", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.SCAN_QRCODE_telegram = +{ + "text": "Please visit: https://diksha.gov.in/help/getting-started/diksha-mobile-app/understanding-qr-code.html. \n\nPress 99 to go back to the previous menu or 0 to the main menu. ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.UNABLE_LOGIN_telegram = +{ + "text": "Please visit: https://diksha.gov.in/help/getting-started/sign-in/index.html. \n\nPress 99 to go back to the previous menu or 0 to the main menu ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.OTHERS_telegram = +{ + "text": "Please visit: https://diksha.gov.in/help/getting-started/explore-diksha/index.html. \n\nPress 99 to go back to the previous menu or 0 to the main menu. ", + "intent": "greet", + "type": "buttons", + "buttons": [] +} + +message.UNKNOWN_OPTION_telegram = +{ + "text": "Sorry, I do not understand what you’re asking. Please choose from the following options or press 0 for the main menu, so I can help you better", + "intent": "greet", + "type": "buttons", + "buttons": [] +} +module.exports.message = message; diff --git a/router/controllers/rasaCoreController.js b/router/controllers/rasaCoreController.js index d6fec04..d59ef22 100644 --- a/router/controllers/rasaCoreController.js +++ b/router/controllers/rasaCoreController.js @@ -8,11 +8,14 @@ const _ = require("lodash") * @param arg2: clientId, client id allocated to the connected session * @param arg3: cb, callback function */ + + //useid has to be added in params function processUserData(data, clientId, cb) { webHookData = { text: data["message"], endpoint: data["endpoint"] } + //pass useid in params API.BOTWebHookAPI(webHookData, clientId, (err, res) => { if (err) { LOG.error(`BOTWebHookAPI failed: ${err}`) From b4f8ff9bc58ab8af15a42682d27514e97a0924c1 Mon Sep 17 00:00:00 2001 From: ajinkyaghodake123 Date: Wed, 19 Aug 2020 11:56:42 +0530 Subject: [PATCH 2/2] code refactoring ith dispatecher and suggestion list chnages --- bot/actions.py | 287 +++++++++++++++------------- bot/data/grades.txt | 10 +- bot/data/nlu.md | 9 + bot/resources/grades.json | 10 + bot/resources/refactored_board.json | 21 ++ 5 files changed, 208 insertions(+), 129 deletions(-) create mode 100644 bot/resources/refactored_board.json diff --git a/bot/actions.py b/bot/actions.py index 227bb68..28f43e6 100644 --- a/bot/actions.py +++ b/bot/actions.py @@ -68,14 +68,129 @@ def name(self) -> Text: def required_slots(tracker: Tracker) -> List[Text]: return ["board", "medium", "grade"] + def board_db(self, value): + print("inside board_db ", value) + board_list = [] + global channel_response + channel_response = requests.get( + "https://staging.ntp.net.in/api/channel/v1/read/0126632859575746566") + + res_json = channel_response.json() + + api_matching_board = self.get_board_api_mapped(value) + channels = res_json['result']['channel']['frameworks'] + for channel in channels: + board_list.append(channel['identifier']) + + return board_list, res_json + + def medium_grade_db(self, medium): + medium_list = [] + global grade_list + grade_list = [] + global medium_grade_categories + grade_mdium_url = "https://staging.ntp.net.in/api/framework/v1/read/" + \ + board_identifier + "?categories=board,medium,gradeLevel,subject" + grade_medium_api_response = requests.get(grade_mdium_url) + res_framwork = grade_medium_api_response.json() + medium_grade_categories = res_framwork['result']['framework']['categories'] + + medium_to_compare = self.get_medium_mapped(medium.lower()) + print("medium_to_compare-->", medium_to_compare) + + for category in medium_grade_categories: + if "medium" in category["code"]: + for term in category["terms"]: + medium_list.append(term['name']) + if medium_to_compare in term["name"]: + medium_available = True + for association in term["associations"]: + if association["category"] == "gradeLevel": + grade_list.append(association['description']) + + print("medium matched-->", medium_available) + break + return medium_list + + def grade_db(self, grade): + + grade_to_compare = self.get_grade_mapped(grade.lower()) + print("grade_to_compare-->", grade_to_compare) + + print("grade_list in grade_db-->", grade_list) + return grade_list + + def validate_board(self, + value: Text, + dispatcher: CollectingDispatcher, + tracker: Tracker, + domain: Dict[Text, Any]) -> Text: + global board_identifier + board_list, res_json = self.board_db(value) + api_matching_board = self.get_board_api_mapped(value.lower()) + if(api_matching_board in board_list): + board_identifier = api_matching_board + return value + else: + get_reafactored_board = [] + get_reafactored_board = self.get_reafactored_board_mapped( + board_list) + elements = [{ + "blocks": [{ + "intent": "greet", + "text": "Available boards are {board} :
".format(board=get_reafactored_board), + "type": "response" + }] + }] + dispatcher.utter_message(json_message=elements) + return None + + def validate_medium(self, + value: Text, + dispatcher: CollectingDispatcher, + tracker: Tracker, + domain: Dict[Text, Any]) -> Text: + # """Validate cuisine value.""" + medium_list = self.medium_grade_db(value) + api_matching_medium = self.get_medium_mapped(value.lower()) + if (api_matching_medium in medium_list): + return value + else: + elements = [{ + "blocks": [{ + "intent": "greet", + "text": "Available mediums for {board} board are :
{medium}".format( + board=tracker.get_slot('board'), medium=medium_list), + "type": "response" + }] + }] + dispatcher.utter_message(json_message=elements) + return None + + def validate_grade(self, + value: Text, + dispatcher: CollectingDispatcher, + tracker: Tracker, + domain: Dict[Text, Any]) -> Text: + grades = self.grade_db(value) + api_matching_grade = self.get_grade_mapped(value.lower()) + if (api_matching_grade in grades): + return value + else: + elements = [{ + "blocks": [{ + "intent": "greet", + "text": "Available grades for {medium} medium in {board} board are :
{grades}".format( + medium=tracker.get_slot('medium'), board=tracker.get_slot('board'), grades=grade_list), + "type": "response" + }] + }] + dispatcher.utter_message(json_message=elements) + return None + def submit(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]: - base_url = "https://diksha.gov.in/explore" - - board_url = "https://staging.ntp.net.in/api/channel/v1/read/0126632859575746566" - - filter_url = "https://staging.ntp.net.in/api/framework/v1/read/ka_k-12_1?categories=board,medium,gradeLevel,subject" print("inside content_form") @@ -87,156 +202,72 @@ def submit(self, dispatcher: CollectingDispatcher, print('Medium -->', medium) print('Board -->', board) - channel_response = requests.get( - "https://staging.ntp.net.in/api/channel/v1/read/0126632859575746566") - # print("board_response-->", response.json()) - res_json = channel_response.json() - # print("type-->", type(response.json())) - # print("result-->",res_json['result']['channel']['frameworks']) - api_matching_board = self.get_board_api_mapped(board.lower()) - print("api_matching_board-->", api_matching_board) - channels = res_json['result']['channel']['frameworks'] - for channel in channels: - # print("x-->",x) - if api_matching_board in channel['identifier']: - board_identifier = channel['identifier'] - print("present in the list-->") - print("x[identifier]-->", channel['identifier']) - - if board_identifier: - print("inside if-->") - grade_mdium_url = "https://staging.ntp.net.in/api/framework/v1/read/" + \ - board_identifier + "?categories=board,medium,gradeLevel,subject" - print("grade_mdium_url-->", grade_mdium_url) - grade_medium_api_response = requests.get(grade_mdium_url) - res_framwork = grade_medium_api_response.json() - categories = res_framwork['result']['framework']['categories'] - # print("frameworks-->",categories) - - grade_to_compare = self.get_grade_mapped(grade.lower()) - print("grade_to_compare-->", grade_to_compare) - - medium_to_compare = self.get_medium_mapped(medium.lower()) - print("medium_to_compare-->", medium_to_compare) - - for category in categories: - if "medium" in category["code"]: - print("medium matched-->", category["code"]) - for term in category["terms"]: - if medium_to_compare in term["description"]: - print("medium matched") - break - # else : - # print("this medium is not available") - # dispatcher.utter_message(text = "this medium is not available for the mentioned board") - - # if "gradeLevel" in category["code"] : - # print("gradeLevel matched-->", category["code"]) - # for term in category["terms"]: - # if grade_to_compare in term["description"]: - # print("grade matched") - - # else : - # print("this grade is not available") - # dispatcher.utter_message(text = "this grade is not available for the mentioned medium") - - board_url = "?board=" + self.get_board_mapped(board.lower()) - medium_url = "&medium=" + self.get_medium_mapped(medium.lower()) - grade_url = "&gradeLevel=" + self.get_grade_mapped(grade.lower()) - url = base_url + board_url + medium_url + grade_url - - # returnObject = [{"type":"buttons","data":{"text":" Great! I understand that you are looking for content of "+ board + " board, class " + grade + ", " + medium + " medium .
" - # "Please visit: DIKSHA " + board + " Board
","intent":"greet","buttons":[]}}] - # print("returnObject-->",returnObject) - # dispatcher.utter_message(json_message = returnObject) - - print("Great! I understand that you are looking for content of " + board + " board, class " + grade + ", " + medium + " medium .
" - "Please visit: DIKSHA " + board + " Board
") - - # elements = [{ - # "type": "buttons", - # "data": { - # "text": "Please visit DIKSHA CHANDIGARH
Select the Medium and Class to view relevant subject textbook on the board website.
", - # "intent": "greet", - # "buttons": [{ - # "text": "Go Back", - # "value": "99", - # }, - # { - # "text": "Main Menu", - # "value": "0", - # }] - # } - # }] - # elements = [{"type":"button", "data" : {"intent" : "greet", "buttons" : [] "text" : " Great! I understand that you are looking for content of "+ board + " board, class " + grade + ", " + medium + " medium .
" - # "Please visit: DIKSHA " + board + " Board
"} }] - - # dispatcher.utter_message(json_message=elements) - - - # dispatcher.utter_message( - # text = { - # "data": { - # "text": " Great! I understand that you are looking for content of "+ board + " board, class " + grade + ", " + medium + " medium .
" - # "Please visit: DIKSHA " + board + " Board
" - # } - # } - # ) - elements = [{ - "blocks": [{ - "intent": "greet", - "text": " Great! I understand that you are looking for content of " + board + " board, class " + grade + ", " + medium + " medium .
" - "Please visit: DIKSHA " + board + " Board
", - "type": "response" - }] - }] - dispatcher.utter_message(json_message=elements) - # elements = [{"type":"weather_action","entities":tracker.latest_message.get('entities'), "loc" : "abc", "intent" : "weather_action"}] - # dispatcher.utter_message(json_message=elements) - # dispatcher.utter_message(text=" Great! I understand that you are looking for content of " + board + " board, class " + grade + ", " + medium + " medium .
" - # "Please visit: DIKSHA " + board + " Board
") - else: - print("enter valid board") + url = self.gererate_diksha_url(board, medium, grade) + + elements = [{ + "blocks": [{ + "intent": "greet", + "text": " Great! I understand that you are looking for content of " + board + " board, class " + grade + ", " + medium + " medium .
" + "Please visit: DIKSHA " + board + " Board
", + "type": "response" + }] + }] + dispatcher.utter_message(json_message=elements) + # dispatcher.utter_message(text=" Great! I understand that you are looking for content of " + board + " board, class " + grade + ", " + medium + " medium .
" + # "Please visit: DIKSHA " + board + " Board
") + return [SlotSet('board', board), SlotSet('grade', grade), SlotSet('medium', medium)] - # def gererate_diksha_url(self): + def gererate_diksha_url(self, board, medium, grade): + print("inside gererate_diksha_url") + base_url = "https://diksha.gov.in/explore" + board_url = "?board=" + self.get_board_mapped(board.lower()) + medium_url = "&medium=" + self.get_medium_mapped(medium.lower()) + grade_url = "&gradeLevel=" + self.get_grade_mapped(grade.lower()) + url = base_url + board_url + medium_url + grade_url + return url def get_board_api_mapped(self, board): - # print("get_board_mapped called") - data = '' dirname = os.path.dirname(__file__) filename = os.path.join(dirname, 'resources/boards_api.json') with open(filename) as boards_api_values: data = json.load(boards_api_values) - print("data in api mapping-->", data[board]) return data[board] + def get_reafactored_board_mapped(self, board_list): + dirname = os.path.dirname(__file__) + reafactored_board_list = [] + filename = os.path.join(dirname, 'resources/refactored_board.json') + with open(filename) as reafactored_boards_values: + data = json.load(reafactored_boards_values) + + for board in board_list: + if board in data: + reafactored_board_list.append(data[board]) + + else: + reafactored_board_list.append(board) + print("reafactored_board_list-->", reafactored_board_list) + return reafactored_board_list + def get_board_mapped(self, board): - # print("get_board_mapped called") - data = '' dirname = os.path.dirname(__file__) filename = os.path.join(dirname, 'resources/boards.json') with open(filename) as boards_values: data = json.load(boards_values) - print("data in board-->", data[board]) return data[board] def get_medium_mapped(self, medium): - # print("get_medium_mapped called") - data = '' dirname = os.path.dirname(__file__) filename = os.path.join(dirname, 'resources/mediums.json') with open(filename) as mediums_values: data = json.load(mediums_values) - # print("data in medium-->",data) return data[medium] def get_grade_mapped(self, grade): - # print("get_grade_mapped called") - data = '' dirname = os.path.dirname(__file__) filename = os.path.join(dirname, 'resources/grades.json') with open(filename) as grades_values: data = json.load(grades_values) - # print("data in grade-->",data) return data[grade] diff --git a/bot/data/grades.txt b/bot/data/grades.txt index f746772..8e3e7de 100644 --- a/bot/data/grades.txt +++ b/bot/data/grades.txt @@ -8,6 +8,8 @@ seven eight nine ten +eleven +twelve first second third @@ -18,6 +20,8 @@ seventh eighth ninth tenth +eleventh +twelveth 1st 2nd 3rd @@ -28,6 +32,8 @@ tenth 8th 9th 10th +11th +12th 1 2 3 @@ -37,4 +43,6 @@ tenth 7 8 9 -10 \ No newline at end of file +10 +11 +12 \ No newline at end of file diff --git a/bot/data/nlu.md b/bot/data/nlu.md index 1faf6f2..7ece06e 100644 --- a/bot/data/nlu.md +++ b/bot/data/nlu.md @@ -143,6 +143,15 @@ - I am from [Marathi](medium) medium - I am in [third](grade) standard and I want to learn [maths](subject) - I want to learn [science](subject) of [bihar](board) board +- [kannada](medium) +- [tenth](grade) +- I am from [hindi](medium) medium +- I am from [class 10](grade) +- i want to learn [class 5](grade) syllabus +- [class 5](grade) +- [tenth](grade) +- [karnataka](board) +- [english](medium) ## lookup:board data/boards.txt diff --git a/bot/resources/grades.json b/bot/resources/grades.json index b5c1b65..7e1d838 100644 --- a/bot/resources/grades.json +++ b/bot/resources/grades.json @@ -47,6 +47,16 @@ "twelveth":"Class 12", "12th":"Class 12", "12":"Class 12", + "class 10": "Class 10", + "class 9": "Class 9", + "class 8": "Class 8", + "class 7": "Class 7", + "class 6": "Class 6", + "class 5": "Class 5", + "class 4": "Class 4", + "class 3": "Class 3", + "class 2": "Class 2", + "class 1": "Class 1", "doctors":"Doctors", "nurses":"Nurses", "nolunteers":"Volunteers", diff --git a/bot/resources/refactored_board.json b/bot/resources/refactored_board.json new file mode 100644 index 0000000..b5b57fd --- /dev/null +++ b/bot/resources/refactored_board.json @@ -0,0 +1,21 @@ +{ + "mh_k-12_15": "Maharashtra", + "up_k-12_5": "UttarPradesh", + "tn_k-12_6": "Tamilnadu", + "nl_k-12": "Nagaland", + "rj_k-12_1": "Rajasthan", + "CBSE": "cbse", + "ka_k-12_1":"Karnataka", + "sk_k-12_2" : "Sikkim", + "JH_K-12-1" : "Jharkhand", + "od_k-12_5" : "odisha", + "ts_k-12_2" : "AndhraPradesh", + "jk_k-12" : "jharkhand", + "gj_k-12" : "gujarat", + "as_k-12_5" : "assam", + "ekstep_ncert_k-12" : "NCERT", + "hr_k-12_1" : "haryana", + "ap_k-12_6" : "andhrapradesh", + "rj_k-12_2" : "rajasthan" + +} \ No newline at end of file