Webhook demo
Tags: #naas #webhook #snippet
Author: Jeremy Ravenel

Basic formulas

Running this command will add your this notebook to the "⚡️ Production" folder. You can then, trigger it with the generated URL.
1
import naas
2
naas.webhook.add()
Copied!
Running this command will delete your webhook
1
naas.webhook.delete()
Copied!

How to use webhook with 3rd party tool?

Use the webhook feature to get data and trigger action from any tool. Example of UMSO - Nocode website builder : https://www.umso.com/

Input

Import library

1
import naas
Copied!

Variables

Add "parameters" tag in cells => Code will be injected after this cell
1
# Parameters
2
params = {}
3
body = {
4
"Domain": "www.naas.ai",
5
"Email": "[email protected]",
6
"Name": "Jeremy",
7
"Site_ID": "jtci2pxwjczr",
8
"Submitted_At": "March 20, 2021 16:55 UTC",
9
}
10
headers = {
11
"host": "public.naas.ai",
12
"x-request-id": "e6b994eb9a83b9cac794c0d9e57c1533",
13
"x-real-ip": "10.0.87.40",
14
"x-forwarded-for": "10.0.87.40",
15
"x-forwarded-host": "public.naas.ai",
16
"x-forwarded-port": "443",
17
"x-forwarded-proto": "https",
18
"x-scheme": "https",
19
"accept": "application/json",
20
"content-type": "application/json",
21
"user-agent": "landen-webhook-agent",
22
"accept-encoding": "gzip",
23
"connection": "close",
24
"content-length": "142",
25
"accept-charset": "utf-8",
26
}
Copied!

Model

Create webhook, get url, add it to your input and test it.

1
naas.webhook.add()
Copied!

Execute webhook and get_output to know the format of parameters injected.

1
naas.webhook.get_output()
Copied!

Thanks to the output notebook, you can understand the structure of your input (standard : params, headers, body).

Inject it in the blank cell in Step 1 to build your pipeline.
1
EMAIL = body.get("Email")
2
EMAIL
Copied!

Build whatever you need.

In this example, I want to send an email with the notebook template to the subscriber.
Setup a notification system.
1
import naas
2
email_to = ["[email protected]", EMAIL]
3
subject = "Get Naas Webhook tutorial template"
4
content = f"Hey {EMAIL},<br>Here is the Naas webhook tutorial template : https://public.naas.ai/amVyZW15LTJFbmFhczQyLTQwZ21haWwtMkVjb20=/asset/7c9359cbc967afd01d8e45b68659b3b0db4179582561f6fab70f156c460a"
5
naas.notifications.send(email_to=email_to, subject=subject, html=content)
Copied!

Output

Share the notebook as an asset.

1
naas.assets.add()
Copied!