使用Visual C#在BOT框架中渲染的自适应卡SDK V4
您好,我已经使用机器人框架 SDK v4 中的核心机器人模板开发了一个聊天机器人,并将其发布在我的 Azure 门户中,并且我能够在网络聊天中打开它。我正在尝试向我的自适应卡添加样式,并且我已检查 Link ,但我无法弄清楚如何渲染我的卡并为其设置 hostconfig.json 。
这是我的 bot.cs 文件
'''
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace asign.Bots
{
public class DialogAndWelcomeBot<T> : DialogBot<T>
where T : Dialog
{
public DialogAndWelcomeBot(ConversationState conversationState, UserState
userState, T dialog, ILogger<DialogBot<T>> logger)
: base(conversationState, userState, dialog, logger)
{
}
protected override async Task OnMembersAddedAsync(IList<ChannelAccount>
membersAdded, ITurnContext<IConversationUpdateActivity> turnContext,
CancellationToken
cancellationToken)
{
foreach (var member in membersAdded)
{
// Greet anyone that was not the target (recipient) of this message.
// To learn more about Adaptive Cards, see https://aka.ms/msbot-
adaptivecards for more details.
if (member.Id != turnContext.Activity.Recipient.Id)
{
var welcomeCard = CreateAdaptiveCardAttachment();
var response = MessageFactory.Attachment(welcomeCard, ssml: "Welcome
to Bot Framework!");
await turnContext.SendActivityAsync(response, cancellationToken);
await Dialog.RunAsync(turnContext,
ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
}
}
}
// Load attachment from embedded resource.
private Attachment CreateAdaptiveCardAttachment()
{
var cardResourcePath =
GetType().Assembly.GetManifestResourceNames().First(name =>
name.EndsWith("welcomeCard.json"));
using (var stream =
GetType().Assembly.GetManifestResourceStream(cardResourcePath))
{
using (var reader = new StreamReader(stream))
{
var adaptiveCard = reader.ReadToEnd();
return new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(adaptiveCard),
};
}
}
}
}
}
'''
Please help me understand how to add a rendering method to above code and setup hostconfig. I would really appriciate the solution.
Hi I have developed a chatbot using core bot template in bot framework SDK v4 and I have published it in my azure portal, and Im able to open it in webchat. I am trying to add styles to my adaptive card and I have checked Link , but I am not able to figure out how to render my card and set up the hostconfig.json to it.
this is my bot.cs file
'''
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace asign.Bots
{
public class DialogAndWelcomeBot<T> : DialogBot<T>
where T : Dialog
{
public DialogAndWelcomeBot(ConversationState conversationState, UserState
userState, T dialog, ILogger<DialogBot<T>> logger)
: base(conversationState, userState, dialog, logger)
{
}
protected override async Task OnMembersAddedAsync(IList<ChannelAccount>
membersAdded, ITurnContext<IConversationUpdateActivity> turnContext,
CancellationToken
cancellationToken)
{
foreach (var member in membersAdded)
{
// Greet anyone that was not the target (recipient) of this message.
// To learn more about Adaptive Cards, see https://aka.ms/msbot-
adaptivecards for more details.
if (member.Id != turnContext.Activity.Recipient.Id)
{
var welcomeCard = CreateAdaptiveCardAttachment();
var response = MessageFactory.Attachment(welcomeCard, ssml: "Welcome
to Bot Framework!");
await turnContext.SendActivityAsync(response, cancellationToken);
await Dialog.RunAsync(turnContext,
ConversationState.CreateProperty<DialogState>("DialogState"), cancellationToken);
}
}
}
// Load attachment from embedded resource.
private Attachment CreateAdaptiveCardAttachment()
{
var cardResourcePath =
GetType().Assembly.GetManifestResourceNames().First(name =>
name.EndsWith("welcomeCard.json"));
using (var stream =
GetType().Assembly.GetManifestResourceStream(cardResourcePath))
{
using (var reader = new StreamReader(stream))
{
var adaptiveCard = reader.ReadToEnd();
return new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(adaptiveCard),
};
}
}
}
}
}
'''
Please help me understand how to add a rendering method to above code and setup hostconfig. I would really appriciate the solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论