用拖放触发Bot删除SharePoint Online [英] Trigger Bot with Drag & drop SharePoint Online
问题描述
我希望能够通过将本地文件放到我的SharePoint在线站点上来触发他的机器人.
I want to be able to trigger my bot who's on my SharePoint online Site by Droping a local file to him.
我创建了一个WebPart以便在网站上使用该机器人,并将嵌入代码由Azure提供.
I created a WebPart to use this bot on the site, and putting the embed code give by Azure.
但是当我将文件放到bot中时,它会在一个新的标签页中打开文档,向我显示内容.
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
我想像一下通过在iframe上使用包含机器人的放置区来解决问题的方法,但是它不起作用.
I'd imagine some solution by using a drop zone on the iframe which contain the bot, but it's not working.
我访问了一些可以提供帮助的站点,但我真的不知道该如何实现: DirectLine API ,
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
此 GitHub 也可能有用.
推荐答案
您需要处理ondragover和ondrop事件(取消默认行为)并手动发布活动:
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:
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');
});
}
这篇关于用拖放触发Bot删除SharePoint Online的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!