/// <summary>
        /// Creates an <see cref="Activity"/> using the body of a request.
        /// </summary>
        /// <param name="payload">The payload obtained from the body of the request.</param>
        /// <param name="identity">The identity of the bot.</param>
        /// <returns>An <see cref="Activity"/> object.</returns>
        public static Activity PayloadToActivity(WebhookEventData payload, Person identity)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            var activity = new Activity
            {
                Id           = payload.Id,
                Timestamp    = new DateTime(),
                ChannelId    = "webex",
                Conversation = new ConversationAccount
                {
                    Id = payload.MessageData.SpaceId,
                },
                From = new ChannelAccount
                {
                    Id = payload.ActorId,
                },
                Recipient = new ChannelAccount
                {
                    Id = identity.Id,
                },
                ChannelData = payload,
                Type        = ActivityTypes.Event,
            };

            if (payload.MessageData.FileCount > 0)
            {
                activity.Attachments = HandleMessageAttachments(payload.MessageData);
            }

            return(activity);
        }
        /// <summary>
        /// Gets a decrypted <see cref="Message"/> by its Id.
        /// </summary>
        /// <param name="payload">The payload obtained from the body of the request.</param>
        /// <param name="decrypterFunc">The function used to decrypt the message.</param>
        /// <param name="cancellationToken">A cancellation token for the task.</param>
        /// <returns>A <see cref="Message"/> object.</returns>
        public static async Task <Message> GetDecryptedMessageAsync(WebhookEventData payload, Func <string, CancellationToken, Task <Message> > decrypterFunc, CancellationToken cancellationToken)
        {
            if (payload == null)
            {
                return(null);
            }

            return(await decrypterFunc(payload.MessageData.Id, cancellationToken).ConfigureAwait(false));
        }
Example #3
0
        /// <summary>
        /// Creates an <see cref="Activity"/> using the body of a request.
        /// </summary>
        /// <param name="payload">The payload obtained from the body of the request.</param>
        /// <param name="identity">The identity of the bot.</param>
        /// <returns>An <see cref="Activity"/> object.</returns>
        public static Activity PayloadToActivity(WebhookEventData payload, Person identity)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            var activity = new Activity
            {
                Id           = payload.Id,
                Timestamp    = default,
Example #4
0
        public ActionResult ChargifyWebHook()
        {
            //ViewBag.Message = "Your contact page.";

            //var responseText=string.Empty;
            //ChargifyAccountRetrieverSection config = ConfigurationManager.GetSection("chargify") as ChargifyAccountRetrieverSection;
            //ChargifyAccountElement accountInfo = config.GetDefaultOrFirst();

            //HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(accountInfo.Site + "webhooks.format");
            //httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            ////2.Pass the apikey and apipassword of chargify
            //httpWebRequest.Headers.Add("username:"******"password:"******"GET";


            ////https://domainname.chargify.com/

            //return View();

            WebhookEventData webHookdata = new WebhookEventData();

            webHookdata.@event = "signup_success";

            ChargifyAccountRetrieverSection config      = ConfigurationManager.GetSection("chargify") as ChargifyAccountRetrieverSection;
            ChargifyAccountElement          accountInfo = config.GetDefaultOrFirst();
            var sharedKey = accountInfo.SharedKey;

            var signatureHeaderHandle = "X-Chargify-Webhook-Signature-Hmac-Sha-256";
            //string signature = !string.IsNullOrEmpty(signature_hmac_sha_256) ? signature_hmac_sha_256 : this.Request.Headers[signatureHeaderHandle]; // Try and get the signature passed in the request header

            //ChargifyAccountRetrieverSection config = ConfigurationManager.GetSection("chargify") as ChargifyAccountRetrieverSection;
            //ChargifyAccountElement accountInfo = config.GetDefaultOrFirst();

            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(accountInfo.Site + "webhooks.json");

            httpWebRequest.ContentType = "application/x-www-form-urlencoded";
            //2.Pass the apikey and apipassword of chargify
            httpWebRequest.Headers.Add("username:"******"password:"******"GET";


            // var isRequestValid = this.Request.InputStream.IsWebhookRequestValid(sharedKey, signature);

            //if (!isRequestValid) { return new HttpStatusCodeResult(HttpStatusCode.NotAcceptable, "Signature mismatch"); }

            switch (webHookdata.@event)
            {
            case "signup_success":
                break;

            case "signup_failure":
                break;

            case "renewal_success":
                break;

            case "renewal_failure":
                break;

            case "payment_success":
                break;

            case "payment_failure":
                break;

            case "billing_date_change":
                break;

            case "subscription_state_change":
                break;

            case "subscription_product_change":
                break;

            case "subscription_card_update":
                break;

            case "expiring_card":
                break;

            case "customer_update":
                break;

            case "component_allocation_change":
                break;

            case "metered_usage":
                break;

            case "upgrade_downgrade_sucess":
                break;

            case "upgrade_downgrade_failure":
                break;

            case "refund_success":
                break;

            case "refund_failure":
                break;

            case "upcoming_renewal_notice":
                break;

            case "end_of_trial_notice":
                break;

            case "statement_closed":
                break;

            case "statement_settled":
                break;

            case "expiration_date_change":
                break;

            default:
                break;
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
        public ActionResult Webhook(WebhookEventData model, string signature_hmac_sha_256)
        {
            ChargifyAccountRetrieverSection config      = ConfigurationManager.GetSection("chargify") as ChargifyAccountRetrieverSection;
            ChargifyAccountElement          accountInfo = config.GetDefaultOrFirst();
            var sharedKey = accountInfo.SharedKey;

            var    signatureHeaderHandle = "X-Chargify-Webhook-Signature-Hmac-Sha-256";
            string signature             = !string.IsNullOrEmpty(signature_hmac_sha_256) ? signature_hmac_sha_256 : this.Request.Headers[signatureHeaderHandle]; // Try and get the signature passed in the request header
            var    isRequestValid        = this.Request.InputStream.IsWebhookRequestValid(sharedKey, signature);

            if (!isRequestValid)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotAcceptable, "Signature mismatch"));
            }

            switch (model.@event)
            {
            case "signup_success":
                break;

            case "signup_failure":
                break;

            case "renewal_success":
                break;

            case "renewal_failure":
                break;

            case "payment_success":
                break;

            case "payment_failure":
                break;

            case "billing_date_change":
                break;

            case "subscription_state_change":
                break;

            case "subscription_product_change":
                break;

            case "subscription_card_update":
                break;

            case "expiring_card":
                break;

            case "customer_update":
                break;

            case "component_allocation_change":
                break;

            case "metered_usage":
                break;

            case "upgrade_downgrade_sucess":
                break;

            case "upgrade_downgrade_failure":
                break;

            case "refund_success":
                break;

            case "refund_failure":
                break;

            case "upcoming_renewal_notice":
                break;

            case "end_of_trial_notice":
                break;

            case "statement_closed":
                break;

            case "statement_settled":
                break;

            case "expiration_date_change":
                break;

            default:
                break;
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }