Trigger Bot with Drag & drop SharePoint Online

空扰寡人 提交于 2019-12-08 05:22:25

问题


I want to be able to trigger my bot who's on my SharePoint online Site by Droping a local file to him.

I created a WebPart to use this bot on the site, and putting the embed code give by Azure.

But when i drop a file in the bot, it open the document in a new tab showing me the content.

I would like to start the conversation while drop a file like this : Start of bot conversation by putting a file

I'd imagine some solution by using a drop zone on the iframe which contain the bot, but it's not working.

I visit some site who can help but i don't really know how to implement this : Bot in WebChat, DirectLine API, Send Activity to the bot

This GitHub could also be usefull.


回答1:


You'll need to handle the ondragover and ondrop events (cancelling the default behavior) and post the activity manually:

html:

<div id="bot" ondrop="drop_handler(event);" ondragover="dragover_handler(event);" />

Javascript:

const dl = new BotChat.DirectLine({
            secret: 'YourDLSecret',
            webSocket: false
        });

BotChat.App({
            botConnection: dl,
            user: { id: 'userid' },
            bot: { id: 'botid' },
            resize: 'detect'
        }, document.getElementById("bot"));

function dragover_handler(ev) {
            console.log("dragOver");
            ev.preventDefault();
        }

function drop_handler(ev) {
    console.log("Drop");

    ev.preventDefault();
    ev.stopPropagation();

    var files = [];
    for (var i = 0; i < ev.dataTransfer.items.length; i++) {
        // If dropped items aren't files, reject them
        if (ev.dataTransfer.items[i].kind === 'file') {
            var file = ev.dataTransfer.items[i].getAsFile();
            files.push({
                contentType: file.type,
                contentUrl: window.URL.createObjectURL(file),
                name: file.name
            });
        }
    }


    dl.postActivity({
        from: { id: 'userid' },
        type: 'message',
        attachments: files 
    })
    .subscribe(function (id) {
        console.log('files sent');
    });

}


来源:https://stackoverflow.com/questions/50581375/trigger-bot-with-drag-drop-sharepoint-online

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!