@larksuiteoapi/node-sdk 1.54.0 → 1.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -491,15 +491,22 @@ const eventDispatcher = new lark.EventDispatcher({
491
491
  router.post('/webhook/event', lark.adaptKoaRouter(eventDispatcher));
492
492
  server.use(router.routes());
493
493
  server.listen(3000);
494
- ````
494
+ ```
495
+
495
496
  #### Custom adapter
496
- 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:
497
+
498
+ 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:
497
499
 
498
500
  ```typescript
499
501
  const data = server.getData();
500
- const result = await dispatcher.invoke(data);
502
+ const headers = server.getHeaders();
503
+ const assigned = Object.assign(
504
+ Object.create({ headers }),
505
+ data,
506
+ );
507
+ const result = await dispatcher.invoke(assigned);
501
508
  server.sendResult(result);
502
- ````
509
+ ```
503
510
 
504
511
  #### Challenge check
505
512
  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)
package/README.zh.md CHANGED
@@ -492,12 +492,19 @@ router.post('/webhook/event', lark.adaptKoaRouter(eventDispatcher));
492
492
  server.use(router.routes());
493
493
  server.listen(3000);
494
494
  ```
495
+
495
496
  #### 自定义适配器
496
- 如果要适配其它库编写的服务,目前需要自己来封装相应的适配器。将接收到的事件数据传递给实例化的`eventDispatcher`的invoke方法进行事件的处理即可:
497
+
498
+ 如果要适配其它库编写的服务,目前需要自己来封装相应的适配器。将接收到的事件数据和请求头传递给实例化的 `eventDispatcher` 的 invoke 方法进行事件的处理即可:
497
499
 
498
500
  ```typescript
499
501
  const data = server.getData();
500
- const result = await dispatcher.invoke(data);
502
+ const headers = server.getHeaders();
503
+ const assigned = Object.assign(
504
+ Object.create({ headers }),
505
+ data,
506
+ );
507
+ const result = await dispatcher.invoke(assigned);
501
508
  server.sendResult(result);
502
509
  ```
503
510