【问题标题】:Trigger Bot with Drag & drop SharePoint Online通过拖放 SharePoint Online 触发机器人
【发布时间】:2018-06-05 07:04:35
【问题描述】:

我希望能够通过将本地文件拖放到我的 SharePoint 在线网站上的机器人来触发他。

我创建了一个 WebPart 来在网站上使用这个机器人,并放置 Azure 提供的嵌入代码。

但是当我在机器人中放置一个文件时,它会在一个新选项卡中打开文档,向我显示内容。

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

我想通过在包含机器人的 iframe 上使用拖放区来实现一些解决方案,但它不起作用。

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

这个GitHub 也很有用。

【问题讨论】:

    标签: sharepoint botframework sharepoint-online


    【解决方案1】:

    您需要处理 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');
        });
    
    }
    

    【讨论】:

    • 谢谢,我试试这个。
    猜你喜欢
    • 2012-03-11
    • 2021-04-26
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 1970-01-01
    • 2017-05-31
    相关资源
    最近更新 更多