How to send an attachment in response from Rasa core action

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.

1 Like

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

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

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.

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

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.

Thanks mate!

Just to be clear. The chatbot can not show a pdf,excel,word,etc file in the chat, even if the chat environment doesn’t recognize it?