public FacebookWebHook()
        {
            Get["/__fbmp/webhook"] = this.HandleRequest(this.WebhookGet);

            Post["/__fbmp/webhook"] = this.HandleRequest(this.WebhookPost);

            Delete["/__fbmp/optin/{type}"] = this.HandleRequest(this.HandleOptOut);
            Post["/__fbmp/optout/{type}"]  = this.HandleRequest(this.HandleOptOut);

            Get["/__fbmp/optin/{type}"] = this.HandleRequest((arg) =>
            {
                return(FacebookWebHook.IsOptInActive(this.SiteDatabase, this.Context, (string)arg.type));
            });

            Get["/__fbmp/linkaccounts"] = this.HandleRequest((arg) =>
            {
                var session = this.SiteDatabase.Query <FacebookChatSession>()
                              .Where(s => s.NcbUserId == 0)
                              .AsEnumerable();

                foreach (var existingSession in session)
                {
                    var customerPSID = existingSession.PageScopedId;

                    // no prior session - see if user have logged in with us before
                    IEnumerable <dynamic> result = FacebookWebHook.FacebookApiGet(this.CurrentSite,
                                                                                  "/" + customerPSID + "/ids_for_apps",
                                                                                  true);

                    var idList = result.FirstOrDefault();

                    if (idList != null) // user have logged in with us before
                    {
                        var id = (string)idList.id;

                        var existingUser = this.SiteDatabase.Query <NcbUser>().Where(u => u.FacebookAppScopedId == id).FirstOrDefault();
                        if (existingUser != null)
                        {
                            existingSession.NcbUserId = existingUser.Id;
                            existingSession.IsRecheckSubscriptionRequired = true;
                            this.SiteDatabase.UpsertRecord(existingSession);

                            if (existingUser.FacebookPageScopedId == null)
                            {
                                existingUser.FacebookPageScopedId = customerPSID;
                                this.SiteDatabase.UpsertRecord(existingUser);
                            }
                        }
                    }
                }

                return("OK");
            });
        }
        public FacebookWebHook()
        {
            Get["/__fbmp/webhook"] = this.HandleRequest(this.WebhookGet);

            Post["/__fbmp/webhook"] = this.HandleRequest(this.WebhookPost);

            Delete["/__fbmp/optin/{type}"] = this.HandleRequest(this.HandleOptOut);
            Post["/__fbmp/optout/{type}"]  = this.HandleRequest(this.HandleOptOut);

            Get["/__fbmp/optin/{type}"] = this.HandleRequest((arg) =>
            {
                return(FacebookWebHook.IsOptInActive(this.SiteDatabase, this.Context, (string)arg.type));
            });
        }