我想知道如何使用 javascript 以编程方式发送消息。 我使用这个脚本来加载 botframework:
(async function() {
const res = await fetch("https://MYURLPRIVATE/api/directline/token", {
"method": "GET"
});
const {
token
} = await res.json();
var t;
t = token;
console.log(token);
var styleOptions = {
hideUploadButton: true,
timestampFormat: 'absolute'
};
const store = window.WebChat.createStore({}, ({
dispatch
}) => next => action => {
return next(action);
});
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({
token
}),
locale: 'it-IT',
styleOptions
}, document.getElementById('chatTranscript'));
document.querySelector('#chatTranscript > *').focus();
})().catch(err => insertError(err))
我用之前分享的脚本创建了一个 pastebin https://pastebin.com/FEYkNd8j
然后 Bot Framework 被加载到一个 DIV 中,带有 id chatTranscript.
我在 div(id chatTranscript)之外还有其他按钮(在用户单击消息后)我想在 bot 框架上发送消息。
我用值“hi”填充输入,并在右键上使用 Jquery 模拟点击。 脚本工作正确,但结果是 hi 这个词在
input type="text"
上消失了,并且没有在 Bot Azure 上发送或/并且没有在 bubble 用户上显示。
那我哪里错了? 你的文档中有一个例子在这个路径:“BotFramework-WebChat\samples .api\d.post-activity-event”但是我不能使用这个脚本
ReactDOM.render("<Composer directLine={directLine}><BasicWebChat /><SendHelpMessageButton /></Composer>,document.getElementById('chatTranscript')");
因为我的服务器上没有ReactJS .
我可以对使用 Javascript 发送消息有一些建议吗? 谢谢