Php 如何使用webchat解决令牌问题
生成directline令牌的bot框架api会生成webchat无法处理的令牌 最近我注意到我网站上的webchat无法再进行directline连接。使用directline secret会产生一个有效的webchat。使用bot framework api生成一个webchat无法处理的很长的令牌(816个字符)(导致类似“无法连接”的消息。这过去工作正常,但现在坏了(据我所知没有任何变化) 我使用一些PHP调用api并获取令牌:Php 如何使用webchat解决令牌问题,php,botframework,token,Php,Botframework,Token,生成directline令牌的bot框架api会生成webchat无法处理的令牌 最近我注意到我网站上的webchat无法再进行directline连接。使用directline secret会产生一个有效的webchat。使用bot framework api生成一个webchat无法处理的很长的令牌(816个字符)(导致类似“无法连接”的消息。这过去工作正常,但现在坏了(据我所知没有任何变化) 我使用一些PHP调用api并获取令牌: <?php $botSecret = 'DI
<?php
$botSecret = 'DIRECLINE SECRET';
$response = wp_remote_get( 'https://webchat.botframework.com/api/tokens', array( 'headers' => 'Authorization: BotConnector ' . $botSecret ) );
if( is_array($response) ) {
$header = $response['headers'];
$token = $response['body'];
}
?>
<script type="text/javascript">
var webChatToken = <?php echo $token; ?>;
</script>
var-webChatToken=;
和Html\Javascript来显示webchat客户端
<html>
<body>
<div id="webchat" role="main"></div>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<script>
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'webchat/join',
value: { language: window.navigator.language }
}
});
}
return next(action);
});
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token: webChatToken }),
store,
styleOptions: {
},
userID: 'N/A',
username: 'Web Chat User',
locale: 'nl-NL'
}, document.getElementById('webchat'));
</script>
</body>
</html>
const store=window.WebChat.createStore({},({dispatch})=>next=>action=>{
如果(action.type==='DIRECT\u LINE/CONNECT\u completed'){
派遣({
键入:“网络聊天/发送事件”,
有效载荷:{
名称:'webchat/join',
值:{language:window.navigator.language}
}
});
}
返回下一步(操作);
});
window.WebChat.renderWebChat({
directLine:window.WebChat.createDirectLine({token:webChatToken}),
商店,
样式选项:{
},
用户ID:'不适用',
用户名:“网络聊天用户”,
区域设置:“nl nl”
},document.getElementById('webchat');
我希望一个较短的令牌或至少一个可用于使用webchat的令牌在webchatclient中使用directline secret会产生一个长度>800的长令牌(长度不同)403错误转化为客户端中的无法连接消息。x。尽管创建连接的方法称为“createDirectLine”,webchat客户端仍然需要webchat机密。BotFramework开发团队刚刚部署了一个更新,允许您在Web聊天端点s上使用DirectLine机密o您现在可以使用DirectLine或WebChat secret将网络聊天连接到您的机器人
const res = await fetch('https://webchat.botframework.com/api/tokens', {
method: 'GET',
headers: {
Authorization: 'BotConnector <WEB_CHAT_SECRET | DIRECT_LINE_SECRET>'
}
});
const token = await res.json();
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token })
}, document.getElementById('webchat'));
const res=wait fetch('https://webchat.botframework.com/api/tokens', {
方法:“GET”,
标题:{
授权:“BotConnector”
}
});
const token=wait res.json();
window.WebChat.renderWebChat({
directLine:window.WebChat.createDirectLine({token})
},document.getElementById('webchat');
希望这有帮助!您是否仍遇到此问题?能否提供有关错误的更多信息?当网络聊天无法连接时,您看到的错误代码是什么?恐怕是。错误是(翻译自荷兰语)“无法建立连接”我现在使用的是一种解决方法,使用直连密码连接。我看不出您的代码有任何明显的问题,并且我能够从您上面使用的端点请求一个令牌来连接到我的机器人。我建议您查看并尝试一下try.Willco.Tnx,以帮助我阅读文档并进行了尝试替代实现。无法运行。您的令牌长度是多少(我得到816个字符的令牌),您是否通过“谢谢”成功连接到您的机器人