Ability to upload attachments as entity and accessing the download URL from Bot Kit


(Subrahmanyam Donepudi) #1

Below is an example to demonstrate the ability to take attachments from the user using entity type “Attachment (Image / File)” and accessing the download URL for the attachment from bot kit.

We have created the dialog “Upload picture” in which fileUpload is an entity node of type “Attachment”.

A webhook node Hook0001 has been added to the fileUpload entity to send the dialog context to the bot kit.

Bot Kit has been configured at the bot and enabled the event -“onHookNode”

At the bot kit, the logic has been written to show the download URL for attachment in the console when the webhook Hook0001 is reached.

on_webhook      : function(requestId, data, componentName, callback) {
        var context = data.context;

          if (componentName === 'Hook0001') {
			  console.log(JSON.stringify(context.session.BotUserSession.channels[0].attachments[0].url.fileUrl));

During runtime, when the attachment is provided by the user from the channel at entity node fileUpload, the dialog context is sent to bot kit and the download URL will be available at below ref path :
context.session.BotUserSession.channels[0].attachments[0].url.fileUrl)

Please refer to below snapshot for more details:
image

Snapshot of the console showing the download URL of attachment provided by the user;

Snapshot showing that the download URL is accessible by accessing the same from browser


Storing an attachment to DB or Service