I want to see a picture of a character named IronMan

@longnguyenQB Don’t be sad please. Share code like action file for blackwidow, or age where you wrote the code.

`dispacture.utter_message(template= "utter_ (what ever you mention in response)`")
return [] 

OR

responses:
utter_(whatever you mention):
 - text: Her is your answer Name: {name} and its Age: {age}

@nik202 I have shared here, this is an example for you to understand, my database is not like this

@longnguyenQB Its very hard for me to understand, but I mention in my above post, hope you understand.

class ActionSearchDocument(Action):

def name(self) -> Text:
    return "action_search_document"

def run(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

    document_name = tracker.get_slot("document_name")
    query_begin = "SELECT name FROM document"
    mycursor.execute(query_begin)
    result_query_begin = mycursor.fetchall()

     # write query
   query_end = "SELECT name, link, date FROM document WHERE name = '" + result_match + "'"

    mycursor.execute(query_end)
    myresult = mycursor.fetchall()
    dispatcher.utter_message(text=f"This is document you want: ")
            dispatcher.utter_message(myresult)

    return []

result : [[“Scientist for beginer”, “https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing”, “2021-07-27 00:00:00”]]

  1. i want my result look like : name : Scientist for beginer , link : https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing , date : 2021-07-27 00:00:00 @nik202

@nik202 this is my code

@longnguyenQB I know only English :stuck_out_tongue: @longnguyenQB the google drive link I can’t understand sorry.

@longnguyenQB In my result the values are name, link and date?

@longnguyenQB After this myresult = mycursor.fetchall() check the output value while using print(myresult) check what values it return.

@longnguyenQB try this

dispatcher.utter_message(text=f"This is document you want: {name}, {link}, {date} ", tracker=tracker)

OR

dispatcher.utter_message(myresult)

@nik202 yes,

  1. result : [[“Scientist for beginer”, “https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing”, “2021-07-27 00:00:00”]]

  2. but i want my result look like : name : Scientist for beginer , link : https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing , date : 2021-07-27 00:00:00 @nik202

@nik202 what is tracker???

if i code : dispatcher.utter_message(myresult)

  1. result : [[“Scientist for beginer”, “https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing” , “2021-07-27 00:00:00”]]
  2. but i want my result look like : name : Scientist for beginer , link : https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing , date : 2021-07-27 00:00:00 @nik202

@longnguyenQB The Tracker class represents a Rasa conversation tracker. It lets you access your bot’s memory in your custom actions. You can get information about past events and the current state of the conversation through Tracker attributes and methods you wrote in def run

@longnguyenQB This pdf is 21 page, what you sharing I can’t get sorry. @longnguyenQB try what I suggested.

it’s just a link, don’t mind it!

@longnguyenQB Then, why you sharing, it not make any sense to me or related to code, you just want to show name, link and age that’s it. rather just share the output, please delete that links, it make other confuse.

@nik202 The link is just part of the output



The result you’re getting is a list of a single list.

myresult = [["Scientist for beginer", "https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing", "2021-07-27 00:00:00"]]
myresult[0] = ["Scientist for beginer", "https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing", "2021-07-27 00:00:00"]

myresult[0][0] = "Scientist for beginer"
myresult[0][1] = "https://drive.google.com/file/d/1V2XS_2pY1yJjDZLJb-P-KoD9UU18N3wF/view?usp=sharing"
myresult[0][2] = "2021-07-27 00:00:00"

So just do this:

myresult = mycursor.fetchall()
message = "name: " + myresult[0][0] + ", link: " + myresult[0][1] + ", date: " + myresult[0][2]

dispatcher.utter_message()
dispatcher.utter_message(myresult)

This is just simple regular Python code, it is not related to Rasa.

Hope this helps!

2 Likes

Ohhhhhhhh right, Chris :face_with_monocle: :face_with_monocle:

@longnguyenQB Please follow Chris advice, it makes a lot of sense if you are expecting the Result which you had shown, and sorry for the confusion, I was expecting BlackWidow and Loki as a result, but by the way are you sure Blackwidow is age 40? :stuck_out_tongue:

Good Luck!

2 Likes

@ChrisRahme Thank you so much, this is exactly what I needed!

1 Like

@nik202 Thank you very much, you have been very helpful to me!

@nik202

I have 1 last problem, hope everyone can help me in this post. when I run rasa shell, input : “tìm kiếm tài liệu đề thi tháng 4” (It’s a request in Vietnamese, translated into English as: searching for April exam papers)

output : “Đấy là thông tin tài liệu đề thi tháng 4:” (translated into English as: This is the April exam paper). The problem here is that the result returned from my database query is a string that is not utf-8. How to fix this last problem? I’m so grateful!

@ChrisRahme the result that I expect from the database query is " Tài liệu đề thi tháng 4" (April exam papers) But the actual result is:"\u0111\u1ec1 thi th\u00e1ng 4"

@longnguyenQB Its encoding UTF-8 issue, try share the code where you fetching .csv file

2 Likes