How to create a Make action with response

Hi guys,

In this video, I show how to create a Pickaxe action that connects to Make and waits for the response.

This is the action code I’ve used:

import os
import requests

def p_make_webhook_response(name: str, email: str, country: str):
"""
Gather details about the user to register him/her to the online webinar

import os
Args:
    name (string): This is the user name
    email (string): user email
    country (string): country of residence
Envs:
    MAKE_SUPPORT_AGENT (string): API for triggering a webhook
"""

# Insert your code below. You can access environment variables using os.environ[].
# Currently, only the requests library is supported, but more libraries will be available soon.
# Use print statements or return values to display results to the user.
# If you save a PNG image in the root directory, it will be automatically displayed to the user.
# You do not have to call this function as the bot will automatically call and fill in the parameters.

# Your Make.com webhook URL
url = os.environ["MAKE_SUPPORT_AGENT"]


# Payload to send with the request --> Adjust based on the function inputs you have set up under action details
payload = {
    "name": name, #ask for the name before sending the request to the webhook
    "email":email, #ask for the email before sending the request to the webhook
    "country":country #ask for the country before sending the request to the webhook
}

# Log payload to verify it
print("Payload being sent:", payload)

# Sending the POST request to the webhook URL
try:
    response = requests.post(url, json=payload, timeout=10)
    
    # Log status code and response content
    print(f"Status code: {response.status_code}")
    print(f"Response content: {response.text}")

    # Check if the request was successful
    if response.status_code == 200:
        # Capture response data
        response_data = response.json()
        print("Webhook sent successfully!")
        print("Response from webhook:", response_data)
        
        # Example: Extracting specific information from the response
        message = response_data.get("message", "No message received")
        additional_info = response_data.get("additional_info", {})
        
        # This is the structure of the data you want Make to return. Add the variables in the body of the webhook response in Make
        ai_response = {
            "name": name,
            "secret_code": secret_code
        }
        print("AI can now process the following data:", ai_response)
    
    else:
        print(f"Failed to send webhook. Status code: {response.status_code}, Response: {response.text}")

except requests.exceptions.Timeout:
    print("The request timed out")
except requests.exceptions.RequestException as e:
    # Handle any request exceptions
    print(f"An error occurred: {e}")

The body of the webhook response in Make is the following:

{
"name" : {{21.name}},
"secret_code": {{random}}
}

Let me know if it helps

2 Likes

Hi there

Many thanks for doing this - I now have everything working the way it should be.

Appreciate it.

1 Like

Thanks for making this informative video about creating actions with Make!

This is a very helpful video. I would like to know how to just send a quick variable in python to the chat without a round trip. So just do some python work and then provide the answer to the chatbot. Do we return a value to the function?

I thought I would go back and try the original one - hoping everything would be good.

I get the same issues:

Please wait while I process your registration

It seems there was an error while processing your registration. Unfortunately, I cannot complete the registration at the moment.

Could you please provide your name, email, and country again? I will ensure that everything is correct this time. Thank you for your patience!

What I find interesting is that the original one I created still works. But all the new ones I am trying to create fail.

Incidentally, I thought I would try a Zapier call - I had no issues

Any ideas?