- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
下面是我为机器人框架编写的代码,我引用了 git hub 中的文档,并关注了很多文章和堆栈溢出的帖子,似乎在 WebChat 行显示机器人时抛出错误。聊天,这里是link也来自 stackoverlflow 中的帖子:
declare var require: any
var React = require('react');
var ReactDOM = require('react-dom');
var DirectLine = require('botframework-directlinejs');
//import * as WebChat from 'botframework-webchat';
var WebChat = require('botframework-webchat');
export class Hello extends React.Component {
constructor() {
super();
this.state = { data: [] };
this.variableValue = { dataValue: [] };
}
async componentDidMount() {
const response = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer secretvalue',
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
accessLevel: 'View',
allowSaveAs: 'false',
})
});
// const { token } = await res.json();
const { token } = await response.json();
console.log(token);
this.setState({ data: token });
//
}
render() {
const {
state: { data }
} = this
return (
//<div>
// <p>Hello there1</p>
// <ul>
// {data}
// </ul>
//</div>
<WebChat.Chat
directLine={{
data,
webSocket: false
}}
style={{
height: '100%',
width: '100%'
}}
//user={{
// id: 'default-user',
// name: 'Some User'
//}}
/>
);
}
}
ReactDOM.render(<Hello />, document.getElementById('root'));
我可以通过休息调用获取 token ,但在必须使用 WebChat.Chat directLine
显示机器人时出现错误以下是错误:
编辑我能够使用react和babel运行html文件中的代码,下面是代码......
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Web Chat: Integrate with React</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--
For simplicity and code clarity, we are using Babel and React from unpkg.com.
-->
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<script src="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee9c8b8f8d9aaedfd8c0dbc0de" rel="noreferrer noopener nofollow">[email protected]</a>/umd/react.development.js"></script>
<script src="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0a2b5b1b3a4fdb4bfbd90e1e6fee5fee0" rel="noreferrer noopener nofollow">[email protected]</a>/umd/react-dom.development.js"></script>
<!--
For demonstration purposes, we are using the development branch of Web Chat at "/master/webchat.js".
When you are using Web Chat for production, you should use the latest stable release at "/latest/webchat.js",
or lock down on a specific version with the following format: "/4.1.0/webchat.js".
-->
<script src="https://cdn.botframework.com/botframework-webchat/master/webchat.js"></script>
<style>
html, body { height: 100% }
body { margin: 0 }
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="webchat" role="main"></div>
<script type="text/babel">
(async function () {
// In this demo, we are using Direct Line token from MockBot.
// To talk to your bot, you should use the token exchanged using your Direct Line secret.
// You should never put the Direct Line secret in the browser or client app.
// https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication
const headers = {"Authorization": "Bearer rngzqJ7rkng.cwA.A8k.xg_Jb-NbNs4Kq8O2CcF-vnNxy8nlCMPMPYaXL0oROr0"}
const body = {"accessLevel": "View"}
//const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', { method: 'POST' }, {Headers:headers},{Body:body});
//const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
method: 'POST',
headers: {
'Authorization': 'Bearer secretvalue',
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
accessLevel: 'View',
allowSaveAs: 'false',
})
});
const { token } = await res.json();
const { ReactWebChat } = window.WebChat;
window.ReactDOM.render(
<ReactWebChat directLine={ window.WebChat.createDirectLine({ token }) } />,
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
</body>
</html>
但是当我在 Node js 应用程序中使用它时,我在使用 WebCHat.Chat 时遇到了问题。
最佳答案
网络聊天有两个版本 - v3 和 v4。您提到的 StackOverflow 问题使用的是 Web Chat v3,而您使用的依赖项是 v4。请查看下面的代码片段,了解使用 Node 实现的 Web Chat v4 的外观。
import React from 'react';
import ReactWebChat, { createDirectLine } from 'botframework-webchat';
export default class extends React.Component {
constructor(props) {
super(props);
this.state = {
directLine: null
};
}
componentDidMount() {
this.fetchToken();
}
async fetchToken() {
const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
const { token } = await res.json();
this.setState(() => ({
directLine: createDirectLine({ token })
}));
}
render() {
return (
this.state.directLine ?
<ReactWebChat
className="chat"
directLine={ this.state.directLine }
/>
:
<div>Connecting to bot…</div>
);
}
}
有关更多详细信息,请查看samples GitHub Repo 上的示例 17 是查看 Node 实现的一个很好的示例。
关于reactjs - 使用 React 的 Azure Bot Framework 存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56630253/
因此,我想创建一个 bot/incoming webhook 来读取群组中的所有消息并将其复制到电子表格中。我在这里要问的是,机器人或传入的 webhook 可以读取整个群组消息吗?在 google
我正在使用 Microsoft Bot Framework 开发一个机器人,在该机器人中,机器人将通过向用户发送一些图像来响应。我用 slack 和 skype 配置了它。 在 slack 中图像正在
我试图让我的机器人与用户开始对话,但我不知道应该从代码中的哪个位置发送消息。启动 convo 的文档在这里,但不是很有帮助:http://docs.botframework.com/connector
我正在创建 Telegram Bot 。我需要跟踪添加用户和添加用户的时间。我如何使用 Telegram API 来做到这一点? 最佳答案 在使用 Telegram API 的群组中,您可以调用 ne
我已经创建了几个 Telegram 机器人。它们适用于我的帐户,也适用于我测试过的其他几个帐户。 但我收到一些用户的报告,称机器人从不响应。 是否有一些用户设置会阻止帐户从机器人获取消息?或者任何其他
如果在一段时间内没有用户输入,我有一个关于取消提示或对话框的问题。 我需要一种方法来以某种方式在提示中超时。 Example: Bot prompts the user: "How old are y
我有一个用例,当我的机器人需要在一天中的特定时间向用户发送消息时。假设每天早上 6 点。 我正在使用预定的 azure Webjob 发送这些消息。消息将在 Slack 和 Skype 客户端中传递。
我是 Microsoft bot 的新手。我的公司有自己的通信应用程序,我想将我的机器人与通信应用程序连接起来,我的客户可以在我公司的通信应用程序上使用我的机器人。我读到它需要使用 Direct Li
我在 sdk V4 Bot 中实现了一个中间件来拦截 bot 和用户之间的每条消息并记录该自定义 mongo Db。我正在尝试为使用 SDK v4 构建的 Bot 实现类似的概念。看起来我可以使用以下
我对编程和学习还很陌生。我认为制作一个不和谐的机器人是一种很好的学习方式,我很享受,只是有点卡住了。所以我的机器人是私有(private)的,我们的不和谐服务器中有一个正在运行的笑话,每当用户发送“k
如何让机器人假装它正在输入消息? 当机器人假装输入时,聊天中会出现以下文本: 我使用 python aiogram框架,但对 native Telegram API 的建议也会有所帮助。 最佳答案 我
我有一个像这样的 Telegram Bot : 通过 webhook 获取更新 语言:C#(我也欢迎其他语言的回答) 我们有以下用户场景: 向机器人发送/MyPhoto a_parameter命令 向
我加入了一个 Telegram Bot ,但我不知道它的所有者。是否可以找到 Telegram Bot 的所有者? 最佳答案 根据 Telegram MTProto protocol 不可能看到 Te
我已经创建了一个电报机器人并按照文档中的描述设置了一个 webhook。出于测试目的,我已经设置了它,因此一旦您向机器人发送一条消息,它就会用相同的消息回复。 现在我遇到的问题是来自电报的更新非常缓慢
是否可以将位置从 Telegram 发送到 Bot,这是在 Bot Framework 中制作的? 我将我的位置从我的 Telegram 帐户发送到我的 Bot,但服务器没有收到它们(我没有收到回复)
我在 Telegram 上创建了一个组并创建了一个机器人并添加进来。 我正在尝试向我创建的组发送消息,错误如下所示 {"ok":false,"error_code":403,"description"
使用 Microsoft Bot Framework V3 我开始使用登录卡。 我从示例代码页做了一个简单的剪切并粘贴到我的代码中,假设它有效(编译): https://docs.botframewo
当用户刚刚打开聊天时,机器人如何向用户发送消息。 例子: 用户已经添加了 Telegram bot到他的联系人列表并开始对话 稍后,用户打开与该机器人的聊天窗口 机器人“看到”该用户已打开聊天窗口,但
将 XCode 更新到版本 11.4 (11E146) 后,我不再在机器人设置中看到存储库分支。但是我在 Source Controll Navigator 中看到了这些存储库分支。有谁知道我该如何解
我想将机器人的位置发送给用户,我在谷歌上搜索了很多,但我发现只有这种情况“将用户的位置发送给机器人”我想要相反的情况,意思是:“发送机器人的位置给用户”。这是我的想法:机器人的所有者是一个司机,他想与
我是一名优秀的程序员,十分优秀!