The Chatbot does not allow to upload files to its own system, but using the Chatbot SDK adapters you can let a user upload a file and store it in your own system for later purposes.
Before implementing the adapter, consider that you need:
Imagine that a variable called file
is responsible for activating the upload media functionality in the Chatbot SDK.
chatbot.subscriptions.onDisplayChatbotMessage((messageData, next) => {
if (messageData && "actionField" in messageData && "variableName" in messageData.actionField) {
if (messageData.actionField.variableName === "file") {
chatbot.actions.showUploadMediaButton();
}
}
next(messageData);
});
We would display the upload media button in the Chatbot SDK when:
onDisplayChatbotMessage
subscription.actionField
).file
.After displaying the button to upload media, we would have to detect when the user uploads a file using the onUploadMedia
subscription.
let fileId;
chatbot.subscriptions.onUploadMedia((mediaData, next) => {
chatbot.actions.hideUploadMediaButton();
chatbot.actions.sendMessage({ message: mediaData.file.name });
uploadFile(mediaData.file).then(response => {
fileId = response;
});
});
Finally, when the file gets uploaded:
uploadFile
method is called. This method uploads the file to an external system and returns the file ID which can be used later to fetch it or send it along other data. This part can be implemented according to your necessities.