Attachment to service API

Is there a way to attach files and use it in service api as file to upload it to other sites

Hi @sureshd,

You can use an entity node with the “Attachment” type which will prompt the user to upload a file and then you can use the entity node output to pass this to the service node API.

Regards,
Yoga Ramya

Hi @yogaramya.mendu ,
In my API I need to give like ‘uploadFile=@ location of the file on file system’, here how can I mention the location in kore.ai

Regards,
Suresh

Hi @sureshd,

When a file is uploaded to the entity node, the file object is returned as per the following screenshot:

image

Also, in the context object >> botUserSession >> channels, you can observe the attachment object.

Let us know if you need any further clarification.

Regards,
Yoga Ramya

Hi @yogaramya.mendu,

I can upload the image file and able to get the url,
image
after that i need to use this image file in a API(service node in kore.ai), by mentioning the filename along with path of the file for example in curl,
curl “https://instance.service-now.com/api/now/attachment/upload
–request POST
–header “Accept:application/json”
–user ‘admin’:‘admin’"
–header “Content-Type:multipart/form-data”
-F ‘table_name=incident’ -F ‘table_sys_id=xxxxxxxxxx’ -F ‘encryption_context=undefined’-F ‘uploadFile=@ location of the file on file system’
So, how to do this in kore.ai service node, for example
image

I tried this, but it is not working

Hi @yogaramya.mendu,

Any update on this?

Here I need to attach the file in API, ‘uploadFile=@ location of the file on file system’.

Regards,
Suresh

Hello sureshd,

Could you solved this issue? I was looking for the same.

Regards

Hi @daniel,

We have discussed this with our internal teams and observed that if your requirement is to pass the uploaded file to an API that can store the file in the required location, then passing the fileUrl alone will not help you achieve the requirement.

The fileUrl that is generated when a file is uploaded is only for one-time use i.e., once the URL is accessed to download the file, then it will be erased.

Hence, to achieve your requirement, we would need to download the file through botKit and then pass it to the respective API.

To understand more on botKit, please find the below documentation link:

https://developer.kore.ai/docs/bots/sdks/using-the-botkit-sdk/

However, we will further discuss this implementation with our development team and will let you know the implementation steps further.

Regards,
Yoga Ramya

Do we have any update here,
Can we attach the file url/location directly to service node?

@pritesh.raka
No in a service node you cannot use a URL to simulate a file attachment. Unless the end API uses a link a downloads the file you cannot use it. The attachment url generated by Kore is one time access only. So, if you need to access the file and pass it on as file, you can download it in botkit, save locally and pass it on to any third party application of your choice.

How do we use bot kit to download the file from the url? We have a similar requirement to download the file in a blob object to use it further to call an API.

@raja.balasubramanian
Since Kore.ai botkit is a NodeJS program, this should be more of a NodeJS question rather than Kore.ai specific capability/platform-related question.

Still, just to see if this helps you, here is a sample code on how this can be done.
NOTE - In no way Kore.ai would prescribe this particular piece of code. This may or may not work for you as is. It is only for a quick PoC. If you are using botkit in a clustered mode, a local file may create inconsistencies in the other botkit cluster instances. This code does not take into account or guarantee all file sizes can be downloaded. Additionally, as mentioned in this thread, the attachment entity fileUrl link will be a one-time access link. If you try that same URL again, it will not work

async function download(fileName, url) {

    https.get(url, (res) => {
        const path = new Date().getTime() + "_" + fileName;
        const writeStream = fs.createWriteStream(path);

        res.pipe(writeStream);

        writeStream.on("finish", () => {
            writeStream.close();
            console.log("Download Completed... " + path);
        });
    });

}

ref: https://sebhastian.com/nodejs-download-file/

Thanks @swagata.sengupta