How to send an attachment in response from Rasa core action


(Akash Vijay) #1

How to send an attachment in response from Rasa core action. For example , User ask for a particular document/template which can be a doc, excel or pdf. how can i return it in response so that it can download at user end.

(ricwo) #2

Hi @Akashvijay22, you cannot directly download files through an action. you could however write a custom action that locates the file, uploads it to a server and returns the download link as an utterance

(Asya K) #3

@ricwo can you share the code snippet for the same?

(Akash Vijay) #4

Hi Asya, If your data is not huge then pass data in json to client( front end ) side and use js libs for download . I did the same for excel file.

(Asya K) #5

i am really new to the whle thing… so…could you share this code for the custom action mentioned here?

(ricwo) #6

Hi Asya, you could just store all your files in, say, Google Drive and keep an index of download links in your custom action. Your action needs to implement logic to find the right file, and you can just utter the download link back to the user, either in plain text or as a HTML if your chat interface support it:

<a href="link to your Google drive file" target="_blank">download here</a>

To do this, use the dispatcher.utter_message method.

(Asya K) #7

Thanks mate!