Skip to content

Instantly share code, notes, and snippets.

💪
On learning spree!

Rahul Patil r4hulp

💪
On learning spree!
Block or report user

Report or block r4hulp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@r4hulp
r4hulp / MessagesController.cs
Created Dec 29, 2017
Bot Framework Messages Controller without DI
View MessagesController.cs
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
@r4hulp
r4hulp / RootDialog.cs
Last active Dec 29, 2017
Root Dialog having constructor with parameters
View RootDialog.cs
[Serializable]
public class RootDialog : IDialog<object>
{
private IProfileService profileService;
public RootDialog(IProfileService profileService)
{
this.profileService = profileService;
}
//code removed for sanity.
@r4hulp
r4hulp / MyBotModules.cs
Last active Dec 29, 2017
Bot Registrations
View MyBotModules.cs
public class MyBotModules : Module
{
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
//Register RootDialog as IDialog<object>
builder.RegisterType<RootDialog>()
.As<IDialog<object>>()
.InstancePerDependency();
View AnyDialog.cs
//In your dialog
Activity message = result as Activity;
//Create scope with respect to activity
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
//Resolve scope for IBotDataStore<BotData>
IBotDataStore<BotData> stateStore = scope.Resolve<IBotDataStore<BotData>>();
/* Retrieve user address. Address key holds information about Bot, Channel, User and conversation */
@r4hulp
r4hulp / AnyDialog.cs
Created Dec 29, 2017
Get Address key from activity
View AnyDialog.cs
Address key = Address.FromActivity(message);
@r4hulp
r4hulp / AnyDialog.cs
Created Dec 29, 2017
Retrieve user data
View AnyDialog.cs
//In your dialog
Activity message = result as Activity;
//Create scope with respect to activity
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
//Resolve scope for IBotDataStore<BotData>
IBotDataStore<BotData> stateStore = scope.Resolve<IBotDataStore<BotData>>();
/* Retrieve user address. Address key holds information about Bot, Channel, User and conversation */
@r4hulp
r4hulp / AnyDialog.cs
Last active Dec 29, 2017
Resolve DataStore scope
View AnyDialog.cs
//In your dialog
Activity message = result as Activity;
//Create scope with respect to activity
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
//Resolve scope for IBotDataStore<BotData>
IBotDataStore<BotData> stateStore = scope.Resolve<IBotDataStore<BotData>>();
}
@r4hulp
r4hulp / Global.asax.cs
Created Dec 29, 2017
Registering module
View Global.asax.cs
//In Global.asax.cs
builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
@r4hulp
r4hulp / add-travis-to-git-repo.bat
Created Jun 9, 2017
Adding Travis.yml to repository
View add-travis-to-git-repo.bat
git add .
git commit -m "added travis.yml"
git push origin master
@r4hulp
r4hulp / travis.yml
Last active Jun 29, 2018
Travis Build Script for Jekyll and Firebase
View travis.yml
#use node_js
language: node_js
#define node js version to use
node_js:
- "7"
#choose branch on commit of which this script should excecute
branches:
only:
You can’t perform that action at this time.