bot Framework WebChat potback按钮在我单击它们后在聊天中显示文本
WebChat版本:4.15.1使用CDN,
描述:我使用带有回发按钮的Herocards,但它们在我单击它们后将其显示为值,也会发生在建议的研究时。由于在某些情况下我使用的是特殊代码,因此我需要将它们隐藏在
卡的用户代码中:
private async Task<DialogTurnResult> ProcesarEnvioMenu(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var tarjetaNecesitoPrueba = new HeroCard()
{
Buttons = new List<CardAction>()
{
new CardAction()
{
Title = "Pruebas",
Type = ActionTypes.PostBack,
Value = "Pruebas"
}
},
Images = new List<CardImage>()
{
new CardImage()
{
Url="https://chatbotfcsblobstorage2.blob.core.windows.net/imagenes/63de5d7e-bf00-498f-bb1a-84c16feef299.png"
}
},
Title = "Necesito una prueba diagnóstica ",
Subtitle = "para saber si tengo COVID"
}.ToAttachment();
var mensaje = stepContext.Context.Activity.CreateReply($"Por favor elige la opción que deseas o si lo prefieres hazme una pregunta directamente.");
mensaje.Attachments = new List<Attachment>();
mensaje.AttachmentLayout = AttachmentLayoutTypes.Carousel;
mensaje.Attachments.Add(tarjetaNecesitoPrueba);
await stepContext.Context.SendActivityAsync(mensaje, cancellationToken: cancellationToken);
return await stepContext.EndDialogAsync();
}
webchat的代码:
<!DOCTYPE html> <html> <head>
<script src="https://cdn.botframework.com/botframework-webchat/4.15.1/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>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
const styleSet = window.WebChat.createStyleSet({
rootHeight: '100%',
rootWidth: '100%',
bubbleFromUserBackground: '#EA431C',
bubbleFromUserBorderRadius: 15,
bubbleFromUserBorderColor: '#EA431C',
bubbleFromUserTextColor: 'White',
bubbleBackground: '#24B5B1',
bubbleBorderRadius: 15,
bubbleBorderColor: '#24B5B1',
bubbleTextColor: 'White',
sendBoxButtonColor: '#0063B1',
sendBoxBorderBottom: 'solid 1px #006FBA',
sendBoxBorderLeft: 'solid 1px #006FBA',
sendBoxBorderRight: 'solid 1px #006FBA',
sendBoxBorderTop: 'solid 1px #006FBA',
suggestedActionBackgroundColor: '#EA431C',
suggestedActionBorderColor: '#EA431C',
suggestedActionBorderColor: 'White',
suggestedActionTextColor: 'White',
suggestedActionBorderStyle: 'none',
suggestedActionBorderRadius: 5,
});
styleSet.textContent = {
...styleSet.textContent,
fontFamily: "'Gotham', 'Calibri', 'Helvetica Neue', 'Arial', 'sans-serif'",
fontColor: 'White'
};
const avatarOptions = {
botAvatarBackgroundColor: '#FE9913',
botAvatarImage: 'https://wikiaprendofcscontainer.blob.core.windows.net/imagenes/wikiaprendo/logowikiaprendofcs.png',
botAvatarInitials: 'BF',
hideUploadButton: true,
};
(async function () {
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'
}
});
}
return next(action); });
const token = '@ViewBag.Token';
var d1 = window.WebChat.createDirectLine({ token })
window.WebChat.renderWebChat({
directLine: Object.assign({}, d1, {
postActivity: activity => {
var newActivity = Object.assign({}, activity, { channelData: { "MonitorId": "@ViewBag.IdMonitor" } });
return d1.postActivity(newActivity);
}
}),
styleSet,
styleOptions:avatarOptions,
store,
sendTypingIndicator:true
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script> </body> </html>
Webchat version: 4.15.1 using CDN,
Description: I am using HeroCards with postback buttons but they show the text in the value after I click them, It also happens with SuggestedActions. Since in some cases I am using special codes I need to hide them from the user
Code of the cards:
private async Task<DialogTurnResult> ProcesarEnvioMenu(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var tarjetaNecesitoPrueba = new HeroCard()
{
Buttons = new List<CardAction>()
{
new CardAction()
{
Title = "Pruebas",
Type = ActionTypes.PostBack,
Value = "Pruebas"
}
},
Images = new List<CardImage>()
{
new CardImage()
{
Url="https://chatbotfcsblobstorage2.blob.core.windows.net/imagenes/63de5d7e-bf00-498f-bb1a-84c16feef299.png"
}
},
Title = "Necesito una prueba diagnóstica ",
Subtitle = "para saber si tengo COVID"
}.ToAttachment();
var mensaje = stepContext.Context.Activity.CreateReply(quot;Por favor elige la opción que deseas o si lo prefieres hazme una pregunta directamente.");
mensaje.Attachments = new List<Attachment>();
mensaje.AttachmentLayout = AttachmentLayoutTypes.Carousel;
mensaje.Attachments.Add(tarjetaNecesitoPrueba);
await stepContext.Context.SendActivityAsync(mensaje, cancellationToken: cancellationToken);
return await stepContext.EndDialogAsync();
}
Code of the webchat:
<!DOCTYPE html> <html> <head>
<script src="https://cdn.botframework.com/botframework-webchat/4.15.1/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>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
const styleSet = window.WebChat.createStyleSet({
rootHeight: '100%',
rootWidth: '100%',
bubbleFromUserBackground: '#EA431C',
bubbleFromUserBorderRadius: 15,
bubbleFromUserBorderColor: '#EA431C',
bubbleFromUserTextColor: 'White',
bubbleBackground: '#24B5B1',
bubbleBorderRadius: 15,
bubbleBorderColor: '#24B5B1',
bubbleTextColor: 'White',
sendBoxButtonColor: '#0063B1',
sendBoxBorderBottom: 'solid 1px #006FBA',
sendBoxBorderLeft: 'solid 1px #006FBA',
sendBoxBorderRight: 'solid 1px #006FBA',
sendBoxBorderTop: 'solid 1px #006FBA',
suggestedActionBackgroundColor: '#EA431C',
suggestedActionBorderColor: '#EA431C',
suggestedActionBorderColor: 'White',
suggestedActionTextColor: 'White',
suggestedActionBorderStyle: 'none',
suggestedActionBorderRadius: 5,
});
styleSet.textContent = {
...styleSet.textContent,
fontFamily: "'Gotham', 'Calibri', 'Helvetica Neue', 'Arial', 'sans-serif'",
fontColor: 'White'
};
const avatarOptions = {
botAvatarBackgroundColor: '#FE9913',
botAvatarImage: 'https://wikiaprendofcscontainer.blob.core.windows.net/imagenes/wikiaprendo/logowikiaprendofcs.png',
botAvatarInitials: 'BF',
hideUploadButton: true,
};
(async function () {
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'
}
});
}
return next(action); });
const token = '@ViewBag.Token';
var d1 = window.WebChat.createDirectLine({ token })
window.WebChat.renderWebChat({
directLine: Object.assign({}, d1, {
postActivity: activity => {
var newActivity = Object.assign({}, activity, { channelData: { "MonitorId": "@ViewBag.IdMonitor" } });
return d1.postActivity(newActivity);
}
}),
styleSet,
styleOptions:avatarOptions,
store,
sendTypingIndicator:true
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script> </body> </html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误是在HTML文件上的网络聊天配置中。这是传达欢迎消息并将参数传递给chatch机器人的正确方法
The error was in the webchat configuration on the html file. This is the right way of having a welcome message AND passing arguments to a chatbot in the channel data