用拖拽触发机器人删除SharePoint Online

时间:2018-05-29 09:53:18

标签: sharepoint botframework sharepoint-online

我希望能够通过删除本地文件来触发我的SharePoint在线网站上的机器人。

我创建了一个WebPart以在网站上使用此bot,并将Azure的嵌入代码放入。

但是当我在机器人中删除文件时,它会在新标签中打开文档,向我显示内容。

我想在删除这样的文件时开始对话: Start of bot conversation by putting a file

我想通过在包含机器人的iframe上使用放置区来想象一些解决方案,但它无效。

我访问了一些可以提供帮助的网站,但我真的不知道如何实现这一点:Bot in WebChatDirectLine APISend Activity to the bot

GitHub也可能有用。

1 个答案:

答案 0 :(得分:0)

您需要处理ondragover和ondrop事件(取消默认行为)并手动发布活动:

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');
    });

}
相关问题