我使用Microsoft Bot Framework开发机器人。用户可以采用以下格式发出搜索命令:" @bot search"然后是搜索词。搜索结果显示为轮播。旋转木马下面是一个按钮,用于优化搜索"。按钮单击应预先填充用户输入区域中的上一个搜索命令。这样,用户可以编辑先前的搜索查询,而无需再次重新键入。这可能吗?
答案 0 :(得分:0)
至于将先前输入的文本插入用户的文本框中,我认为你不能这样做。
如果将自适应卡与Bot Framework一起使用,则可以使用具有text属性的Adaptive Card对象,并设置按钮的动作以发送消息。可以在“优化搜索”中将文本设置为您想要的任何内容。这是node.js中的一个例子:
var restify = require('restify');
var builder = require('botbuilder');
var adaptive = require('adaptivecards');
let Adapt = () => {
var inMemoryStorage = new builder.MemoryBotStorage();
let response = "";
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
// your app ID and password here
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
// Bot structure. It will use an AdaptiveCard, and you will be able to refine the search in the textbox inside the card itself. Search will send the textbox's text to the bot and it will bring the card back up again with the updated text.
var bot = new builder.UniversalBot(connector, function (session) {
if (!!session.message.value && !!session.message.value.refineSearchText) {
response = session.message.value.refineSearchText;
} else {
response = "";
}
let attachTest = {
'contentType': 'application/vnd.microsoft.card.adaptive',
'content': {
'$schema': 'http://adaptivecards.io/schemas/adaptive-card.json',
'type': 'AdaptiveCard',
'version': '1.0',
'body': [ {"type": "TextBlock", "text": "Refine Search?"},
{
'type': "Input.Text",
"id": "refineSearchText",
"placeholder": "Search to refine",
"style":"text",
"value": `${response || session.message.text}`
}],
'actions': [
{
'type': 'Action.Submit',
'title': 'Search'
}
]
}
};
session.send(`You're refining: ${response}`);
let attachTestMsg = new builder.Message(session).addAttachment(attachTest);
session.send(attachTestMsg);
}).set("storage", inMemoryStorage);
};
Adapt();
如果您没有使用node.js,则可能需要根据您正在使用的环境进行调整。