Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,22 @@ const eventDispatcher = new lark.EventDispatcher({
router.post('/webhook/event', lark.adaptKoaRouter(eventDispatcher));
server.use(router.routes());
server.listen(3000);
````
```

#### Custom adapter
If you want to adapt to services written by other libraries, you currently need to encapsulate the corresponding adapter yourself. Pass the received event data to the invoke method of the instantiated `eventDispatcher` for event processing:

If you want to adapt to services written by other libraries, you currently need to encapsulate the corresponding adapter yourself. Pass the received event data and request headers to the invoke method of the instantiated `eventDispatcher` for event processing:

```typescript
const data = server.getData();
const result = await dispatcher.invoke(data);
const headers = server.getHeaders();
const assigned = Object.assign(
Object.create({ headers }),
data,
);
const result = await dispatcher.invoke(assigned);
server.sendResult(result);
````
```

#### Challenge check
When configuring the event request address, The Open Platform will push a POST request in `application/json` format to the request address. The POST request is used to verify the validity of the configured request address, and the request body will carry a `challenge` field , **The application needs to return the received challenge value to the Open Platform within 1 second**. See: [ Document](https://open.feishu.cn/document/ukTMukTMukTM/uYDNxYjL2QTM24iN0EjN/event-subscription-configure-/request-url-configuration-case)
Expand Down
11 changes: 9 additions & 2 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,19 @@ router.post('/webhook/event', lark.adaptKoaRouter(eventDispatcher));
server.use(router.routes());
server.listen(3000);
```

#### 自定义适配器
如果要适配其它库编写的服务,目前需要自己来封装相应的适配器。将接收到的事件数据传递给实例化的`eventDispatcher`的invoke方法进行事件的处理即可:

如果要适配其它库编写的服务,目前需要自己来封装相应的适配器。将接收到的事件数据和请求头传递给实例化的 `eventDispatcher` 的 invoke 方法进行事件的处理即可:

```typescript
const data = server.getData();
const result = await dispatcher.invoke(data);
const headers = server.getHeaders();
const assigned = Object.assign(
Object.create({ headers }),
data,
);
const result = await dispatcher.invoke(assigned);
server.sendResult(result);
```

Expand Down