Clustaar Webhook框架
clustaar.webhook的Python项目详细描述
#webhook是为[clustaar平台](https://clustaar.com)构建webhook的框架。
` conversation.step已到达'event.
`` python
从clustaar.webhook导入webhook,events
从clustaar.schemas.models导入stepReachedResponse,conversationSession
def handler(请求、响应、通知):
session=conversationSession(值={“name”:“john”})
返回stepReachedResponse(actions=[],session=session)
app.on(events.conversation\u step\u reached,handler)
`````
\routing
\routing
\event
routing是通过在配置webhook时为“on()”方法指定事件名称来实现的:
``python
app.on(events.conversation\u step\u reached,处理程序)
```
`仅当事件类型为“events.conversation\u step\u reached”且json键“data.step.id”的值等于“507f191e810c1929de860ea”时,处理程序“才会接收请求”:clustaar.webhook.filters import json key equals
app.on(events.conversation\u step\u reached,
handler,
filter=json key equals(“data.step.id”,“507f191e810c1929de860ea”))
````
````jsonkeyequals
验证json密钥是否等于预期值。
``python
data={
“user”:{
“id”:1
}
}
}
filter=jsonkeyequals(“user.id”,
assert-filter(data)
data[“user”][“id”]=2
assert-not-filter(data)
```
在(“user.id”,[1,<数据> [用户] ](3)BR/>断言不过滤(数据)
'BR/>< j/Ky > jSONKEY存在
BR/>验证存在JSON关键字。< BR/>‘Python < BR/>数据= {BR/>“用户”:1
} BR/> } BR/>筛选器= JSONKEY存在(“用户ID”)< BR/>断言
> AsPrter过滤器(数据)
数据[[用户] ] [“ID”]=2<BR/>断言过滤器(数据)数据过滤(data)
deldata[“user”][“id”]
assert not filter(data)
```
}
}
}
=StepID(“507F191E810C19729DE860EAC19729DE860EA”)
>断言过滤器(数据)
>del data[“data”][“step”][“id”]
>断言非过滤器(数据)断言非过滤器(数据)
```
``` ` `
如果将一个步骤ID列表传递给“stepid”过滤器,它将验证列表中是否存在“data.step.id`数据.step.id`列表。
安全
/>////如果请求签名
如果您请求签名
br/>要验证的签名clustaar发送的请求,需要提供私钥。
必须在bot的webhook配置中设置此私钥。
``python
app=webhook(private廑key=“xxxxxxxxx”)
````
配置。
`` python
app=webhook(auth庘username=“xxxxxxxxx”,auth庘password=“yyyyyyyyy”)
```
` conversation.step已到达'event.
`` python
从clustaar.webhook导入webhook,events
从clustaar.schemas.models导入stepReachedResponse,conversationSession
def handler(请求、响应、通知):
session=conversationSession(值={“name”:“john”})
返回stepReachedResponse(actions=[],session=session)
`````
\routing
\routing
\event
routing是通过在配置webhook时为“on()”方法指定事件名称来实现的:
``python
app.on(events.conversation\u step\u reached,处理程序)
```
`仅当事件类型为“events.conversation\u step\u reached”且json键“data.step.id”的值等于“507f191e810c1929de860ea”时,处理程序“才会接收请求”:clustaar.webhook.filters import json key equals
app.on(events.conversation\u step\u reached,
handler,
filter=json key equals(“data.step.id”,“507f191e810c1929de860ea”))
````
````jsonkeyequals
验证json密钥是否等于预期值。
``python
data={
“user”:{
“id”:1
}
}
}
filter=jsonkeyequals(“user.id”,
assert-filter(data)
data[“user”][“id”]=2
assert-not-filter(data)
```
在(“user.id”,[1,<数据> [用户] ](3)BR/>断言不过滤(数据)
'BR/>< j/Ky > jSONKEY存在
BR/>验证存在JSON关键字。< BR/>‘Python < BR/>数据= {BR/>“用户”:1
} BR/> } BR/>筛选器= JSONKEY存在(“用户ID”)< BR/>断言
> AsPrter过滤器(数据)
数据[[用户] ] [“ID”]=2<BR/>断言过滤器(数据)数据过滤(data)
deldata[“user”][“id”]
assert not filter(data)
```
}
}
}
=StepID(“507F191E810C19729DE860EAC19729DE860EA”)
>断言过滤器(数据)
>del data[“data”][“step”][“id”]
>断言非过滤器(数据)断言非过滤器(数据)
```
``` ` `
如果将一个步骤ID列表传递给“stepid”过滤器,它将验证列表中是否存在“data.step.id`数据.step.id`列表。
安全
/>////如果请求签名
如果您请求签名
br/>要验证的签名clustaar发送的请求,需要提供私钥。
必须在bot的webhook配置中设置此私钥。
``python
app=webhook(private廑key=“xxxxxxxxx”)
````
配置。
`` python
app=webhook(auth庘username=“xxxxxxxxx”,auth庘password=“yyyyyyyyy”)
```