clustaar.webhook
clustaar.webhook is a framework to build webhooks for the clustaar platform.
More documentation is available for building webhooks on https://developers.clustaar.com
Example
Here is a webhook that will trigger an handler function each times it receives a conversation.step_reached event.
from clustaar.webhook import Webhook, events
from clustaar.schemas.models import StepReachedResponse, ConversationSession
def handler(request, response, notification):
session = ConversationSession(values={"name": "John"})
return StepReachedResponse(actions=[], session=session)
app = Webhook()
app.on(events.CONVERSATION_STEP_REACHED, handler)
Routing
Event
Routing is achieved by specifying an event name to the on() method while configuring your webhook :
app.on(events.CONVERSATION_STEP_REACHED, handler)
Filters
If you want to add some condition to route events based on the request received you can use filters.
In this example, handler will receive the requests only when the event is of type events.CONVERSATION_STEP_REACHED and the value of the JSON key data.step.id equals "507f191e810c19729de860ea" :
from clustaar.webhook.filters import JSONKeyEquals
app.on(events.CONVERSATION_STEP_REACHED,
handler,
filter=JSONKeyEquals("data.step.id", "507f191e810c19729de860ea"))
JSONKeyEquals
Validates that a JSON key equals an expected value.
data = {
"user": {
"id": 1
}
}
filter = JSONKeyEquals("user.id", 1)
assert filter(data)
data["user"]["id"] = 2
assert not filter(data)
JSONKeyIn
Validates that a key is present in a defined set of values.
data = {
"user": {
"id": 1
}
}
filter = JSONKeyIn("user.id", [1, 2])
assert filter(data)
data["user"]["id"] = 2
assert filter(data)
data["user"]["id"] = 3
assert not filter(data)
JSONKeyExists
Validates that a JSON key is present.
data = {
"user": {
"id": 1
}
}
filter = JSONKeyExists("user.id")
assert filter(data)
del data["user"]["id"]
assert not filter(data)
StepID
Validates that the data.step.id correspond to the expected id.
data = {
"data": {
"step": {
"id": "507f191e810c19729de860ea"
}
}
}
filter = StepID("507f191e810c19729de860ea")
assert filter(data)
del data["data"]["step"]["id"]
assert not filter(data)
If you pass a list of step IDs to the StepID filter it will validate the the data.step.id is present in the list.
Security
Request signature
If you want to validate the signature of the requests sent by clustaar, you need to provide a private key.
This private key must be set in your bot's webhook configuration.
app = Webhook(private_key="XXXXXXXXXX")
Authentication
If you want to add some authentication to your application you can pass the HTTP basic authentication credentials that you defined in your webhook's configuration.
app = Webhook(auth_username="XXXXXXXXXX", auth_password="YYYYYYYYY")
Metadata
Release files for clustaar.webhook 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clustaar.webhook-0.1.7.tar.gz | 25.9 kB | Without provenance | Details for clustaar.webhook-0.1.7.tar.gz |
Release files / clustaar.webhook-0.1.7.tar.gz
| Download URL | clustaar.webhook-0.1.7.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
116ded975aff0993feca81924506af60828a11e0d0802e4ea182961474286688
|
|
BLAKE2b-256 checksum How to use checksums |
825630a1051311262f411ba62a39147ecc495cb3e08e237f25c2436e09d29f52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for clustaar.webhook 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.