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

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”.

image

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”
image

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;
image

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

1 Like

Hi,

Can we upload a file only in talk to bot without using bot kit and web hook ?

Hi @abhijitna,

You can anyway use the fileUpload type entity in “talk to bot” without using bot kit and webhook node.

The uploaded file URL can be accessed through the following snippet:

{{context.entities.EntityName[0].url.fileUrl}}

Please find the attached screenshots for reference:
fileUpload1 fileUpload2 fileUpload3

Let us know if you need any further clarification on the above.

Regards,
Yoga Ramya.

2 Likes

Hi @abhijitna, If I understand the requirement right, your would like to pass the attachment provided by the user via the webSDK channel to the third party application URL using the service node.

This cannot be achieved using the dialog tasks as of now but we have it on our roadmap. The only way you could send the attachment to third party is enable the bot kit at events (say on message or on webhook), use the fileURL present in the context object to download the file into the botkit and then make the call to the third party API from the botkit itself.

A file Upload is feasible using the simple tasks though (Actions, Information tasks, alerts) using the field type “file”. But we got some limitations uploading the files to third party apps depending the way file upload is entertained by the third party.

Hi @Subrahmanyam and @yogaramya.mendu,

is this still working? I have an intent equal to the @yogaramya.mendu intent, and when the Intent is fired, this entity ask to the user by the file. I upload an image but after that I’m always getting a message from bot saying “I don’t know what you want me to do.”… can you give me a help?

19

thanks

Can we already do this via service node? If yes, how can we do it? Maybe an example with mocki api

@daniel,

Please refer Attachment to service API

Regards,
Yoga Ramya

Hi,

Could you please help me with the configurations for teams channel for the same scenario. Kindly let me know how to make the bot recognize the intent once attachment is uploaded

Thanks,
viji

Hello @vijayalakshmigananat ,

Intent detection comes first, i.e, once an intent is detected, the respective dialog is triggered and the user is prompted to upload the file. This process is the same for any channel and is driven by the dialog flow.

Please clarify your requirement. The original post is regarding Attachment entity and how to access/process the uploaded file.

Hi Sameera,

My requirement is that, when a user directly uploads an image, how can we extract the image URL.

Thanks,
Viji

Hello @vijayalakshmigananat ,

So your requirement is, if our understanding is correct, when a uploads a file to the chat window, without having an active conversation/session, Bot should automatically detect user input, and based on that trigger a dialog to capture the file as an entity response.

Unless you are in the bot context, and bot is awaiting a file input, i.e, attachment entity node is triggered, the uploaded file will not be recognized.

The same logic applies to teams as well. If you are in a bot context however, you can use the method mentioned above to obtain the link for the attachment and use it as required.