Search code examples
pythonamazon-web-servicesslackaws-lex

Uploading a file to Amazon Lex


I'm creating a chatbot with Amazon Lex and the idea is that a user can drop an Excel file into a Slack channel and the bot sends the file to the appropriate Lambda function. What is the best way to achieve this goal?

It would also be acceptable if the Lex bot uploads the file somewhere else accessible (s3, EC2, Github, etc.) and then sends the address to the Lambda functions.

I do not see any SlotTypes that support this type of input.


Solution

  • Lex PostText or PostContent method doesn't support the upload load files.

    • where as in slack you will get the file url in payload when user uploads a file.
    • Create slot type Eg.- File. keep the enumeration value as uploaded.
    • When slotToElicit is File check whether url is exists or not in the payload. if exists send the URL to lex using the session attributes and fill the slot value as Uploaded(Default value). If user doesn't upload a file fill the slot value with some random text to elicit the slot again.
    • With the help of Session attributes you can have access to file and upload it to S3.