How to create a table-like response?

Hello everyone,

This is my custom action:

class ActionFetchConferences(Action):

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

    async def run(self,
                  dispatcher: CollectingDispatcher,
                  tracker: Tracker,
                  domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
            """ Will bring the requested conferences to the user"""

            category = tracker.get_slot("category")
            sheetsname = tracker.get_slot("sheetsname")

            conferences_df = pd.read_excel(".\\Conferences.xlsx", sheet_name=sheetsname)

            # if category:
            #     userConferencesOfChoice = conferences_df.loc[:, category]
            # else:
            #     userConferencesOfChoice = conferences_df
                
            # dispatcher.utter_message(text="All done!")

            # print(userConferencesOfChoice)
            print(conferences_df)
            return []

I want to return to the user a table-like response. This line print(conferences_df) does nothing. And if uncomment the above lines I am getting a dictionary attribute error.

I would like to ask if I am approaching in the right way the problem of returning a table-like response and if yes what should I correct to this code?

Hello!

Can you show what you mean by “table-like response”?

If you want to display a table, you will have to implement that in your front-end application.

Or, alternatively, you can convert this table as an image in the Custom Action, and then show that image to the user with dispatcher.utter_message(image = image_path).

print(message) will print the message in the terminal where you ran rasa run actions. If you want to show text to the user, you need dispatcher.utter_message(text = text).

Hey @ChrisRahme , thank you for your response.

I am still using only the terminal, so I was thinking of a table-like form as below:

| Index | Column1    | Column2    |
| row1  | some_value | some_value |
| row2  | some_value | some_value |

I hope it makes sense. But, I think your suggestion of an image is something to start with.

So you want to display a table with the | characters, not an HTML table (for example). I’m sure there’s a code somewhere on GitHub or StackOverflow to convert a dictionary to an ASCII table :slight_smile:

Take a look at this: Is there's any python library to output dictionary in beautiful ascii table? - Stack Overflow

Cool, thank you!

1 Like