Some Classes to create a command driven bot with the Microsoft BotFramework and some helpfull extensions.
Style a given string with Markdown.
"Bold".MakeBold()
=> Bold
"Italic".MakeItalic()
=> Italic
"Code".MakeInlineCode()
=> Code
"http://github.com".MakeHyperlink("github")
=> github
"line".AddLineBreak()
Creates LineBreak after line
var testCommands = new CommandList()
{
{
"command1", new Parameters(
"command1-no",
async c =>
{
await c.Activity.GetConnectorClient().Conversations.ReplyToActivityAsync(c.Activity.CreateReply("1: No Parameter"));
})
},
{
"command1", new Parameters(
"comand1-two",
async c =>
{
await c.Activity.GetConnectorClient().Conversations.ReplyToActivityAsync(c.Activity.CreateReply("1: Two Parameters: " + c.Parameters[0] + " " + c.Parameters[1]));
},
ParameterType.Integer,
ParameterType.Boolean)
},
{
"command2", new Parameters(
"command2",
async c =>
{
await c.Activity.GetConnectorClient().Conversations.ReplyToActivityAsync(c.Activity.CreateReply("2: No Parameter"));
})
},
};
if (!await testCommands.InvokeAsync(activity))
{
await activity.GetConnectorClient().Conversations.ReplyToActivityAsync(activity.CreateReply("No match!"));
}
var data = activity.GetStateClient().BotState.GetUserDataProperty<PropertyType>(activity.ChannelId, activity.From.Id, "propertyKey");
activity.GetStateClient().BotState.SetUserDataProperty(activity.ChannelId, activity.From.Id, "propertyKey", data);
var sticker = Telegram.GetSticker(activity);
if (sticker != null)
{
var reply = activity.CreateReply();
reply.ChannelData = Telegram.SendSticker(sticker);
await activity.GetConnectorClient().Conversations.ReplyToActivityAsync(reply);
}
var location = Telegram.GetLocation(activity);
if (location != null)
{
var reply = activity.CreateReply();
reply.ChannelData = Telegram.SendLocation(location);
await activity.GetConnectorClient().Conversations.ReplyToActivityAsync(reply);
}
var contact = Telegram.GetContact(activity);
if (contact != null)
{
var reply = activity.CreateReply();
reply.ChannelData = Telegram.SendContact(contact);
await activity.GetConnectorClient().Conversations.ReplyToActivityAsync(reply);
}
var reply = activity.CreateReply();
reply.ChannelData = Telegram.EditMessage(messageIdToChange, "New Message");
await activity.GetConnectorClient().Conversations.ReplyToActivityAsync(reply);
Some Classes to parse csv, html or xml files.
var client = new WebClient
client.Encoding = Encoding.UTF8;
var site = client.DownloadString("http://github.com");
var parsed = HtmlParser.ParseHtml(site);
// Get string in title
var tag = parsed.GetTagsWithTag("title").First();
var title = tag.ChildContent.First();