简体   繁体   中英

How do I get response data sent back to Zapier using the Custom Action function with WP Webhooks and Wordpress?

I'm trying to generate a Zoom SDK signature using my wordpress custom function.php file. I am able to send a post to WP Webhooks using Zapier to fire a Custom Function. I use the identifier and get the response "success, custom action successfully fired." However, it will not return the SDK signature to Zapier.

This is the PHP code that is run on a custom action.

 function generate_signature ( $api_key, $api_secret, $meeting_number, $role){
   //Set the timezone to UTC
   date_default_timezone_set("UTC");
    $time = time() * 1000 - 30000;//time in milliseconds (or close enough)
    $data = base64_encode($api_key . $meeting_number . $time . $role);
    $hash = hash_hmac('sha256', $data, $api_secret, true);
    $_sig = $api_key . "." . $meeting_number . "." . $time . "." . $role . "." . base64_encode($hash);
     //return signature, url safe base64 encoded
     return rtrim(strtr(base64_encode($_sig), '+/', '-_'), '=');

}

I've also tried returning the data using the $return_args portion of the sample code provided by WP Webhooks. The sample code is below:

 add_filter( 'wpwhpro/run/actions/custom_action/return_args', 'wpwh_fire_my_custom_logic', 10, 3 );
 function wpwh_fire_my_custom_logic( $return_args, $identifier, $response_body ){

    //If the identifier doesn't match, do nothing
    if( $identifier !== 'ilovewebhooks' ){
        return $return_args;
     }

    //This is how you can validate the incoming value. This field will return the value for the key user_email
    $email = WPWHPRO()->helpers->validate_request_value( $response_body['content'], 'user_email' );

    //Include your own logic here....

    //This is what the webhook returns back to the caller of this action (response)
    //By default, we return an array with success => true and msg -> Some Text
    return $return_args;

 }

I'm not sure how to format this code properly to fire the code given above to generate the SDK signature, and then return that within the $return_args back to the webhook that called it by Zapier?

Thank you for any help you can provide!

You can just return the data by assigning the function response to the $return_args :

    $return_args['data'] = generate_signature();

In your full example, it looks something like this:

add_filter( 'wpwhpro/run/actions/custom_action/return_args', 'wpwh_fire_my_custom_logic', 10, 3 );
 function wpwh_fire_my_custom_logic( $return_args, $identifier, $response_body ){
    //If the identifier doesn't match, do nothing
    if( $identifier !== 'ilovewebhooks' ){
        return $return_args;
     }

    //This is how you can validate the incoming value. This field will return the value for the key user_email
    $email = WPWHPRO()->helpers->validate_request_value( $response_body['content'], 'user_email' );

    $return_args['data'] = generate_signature();

    //This is what the webhook returns back to the caller of this action (response)
    //By default, we return an array with success => true and msg -> Some Text
    return $return_args;

 }

You'll find more details about that here: https://wp-webhooks.com/integrations/wordpress/actions/custom_action/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM