Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #108 to Support CustomEventHandler decryptEvent #109

Open
wants to merge 1 commit into
base: v2_main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* MIT License
*
* Copyright (c) 2022 Lark Technologies Pte. Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.lark.oapi.event;

import com.lark.oapi.event.model.BaseEvent;

public abstract class CustomEventV1Handler<T extends BaseEvent> implements IEventHandler<T> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* MIT License
*
* Copyright (c) 2022 Lark Technologies Pte. Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.lark.oapi.event;

import com.lark.oapi.event.model.BaseEventV2;

public abstract class CustomEventV2Handler<T extends BaseEventV2> implements IEventHandler<T> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,30 @@ public Builder onCustomizedEvent(String eventType, CustomEventHandler handler) {
return this;
}


/**
* 订阅事件扩展:开发者可自己传递事件类型,并传递对应事件类型的处理器
*/
public <T extends BaseEvent> Builder onCustomizedEvent(String eventType, CustomEventV1Handler<T> handler) {
if (eventType2EventHandler.containsKey(eventType)) {
throw new EventTypeAlreadyHasHandlerException(eventType);
}
eventType2EventHandler.put(eventType, handler);
return this;
}


/**
* 订阅事件扩展:开发者可自己传递事件类型,并传递对应事件类型的处理器
*/
public <T extends BaseEventV2> Builder onCustomizedEvent(String eventType, CustomEventV2Handler<T> handler) {
if (eventType2EventHandler.containsKey(eventType)) {
throw new EventTypeAlreadyHasHandlerException(eventType);
}
eventType2EventHandler.put(eventType, handler);
return this;
}

/**
* <p> 用户阅读机器人发送的消息后触发此事件。
* <p> 事件描述文档链接:<a href="https://open.feishu.cn/document/ukTMukTMukTM/ugzMugzMugzM/event/message-read">https://open.feishu.cn/document/ukTMukTMukTM/ugzMugzMugzM/event/message-read</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,39 @@ public void handle(P2MessageReceiveV1 event) {
assert resp != null;

}

@Test
public void testProcessCustomEncyEvent() throws Throwable {
EventDispatcher eventDispatcher = EventDispatcher.newBuilder("v", "1212121212")
.onCustomizedEvent("contact.user.created_v3", new CustomEventV2Handler<P2UserCreatedV3>() {
@Override
public P2UserCreatedV3 getEvent() {
return new P2UserCreatedV3();
}

@Override
public void handle(P2UserCreatedV3 event) throws Exception {
System.out.println(Jsons.DEFAULT.toJson(event));
System.out.println("---------------------");
System.out.println(Jsons.DEFAULT.toJson(event.getEvent()));
}
})
.build();

String body = "{\"encrypt\":\"4T4ivT/PR2APX9OYkhRKtu54s1rtIpj9xJU69Hs1yWQ/1RutbufsBs9xjx5YC3u/0hMRF49sN0kevQiEL8iB3bVEdpfyJXzXGDfKUjvKQTmG64GbMdTW6qRpadVPem3f32jHuT6fc+4TRg4BigwoUId+l/D+vcIwu3mDgAEbaqzWfmvccmpiRMfQbh9JhdK/akmrRjo/CXPLM+hZciFXJMSpKueV3SjZJoSls5y0ZTHC8zak/Mp/DSl1wa4mYe5laP367Lnl4ylGiXBKx3Ku29oWv79rYcO/5QT63H4rkl8bwYmAzScpb2KNnV11L3xiDzJp3hFdfXczUvm93FXu4Lw8eDAsRzIWCccKrqHh0UvtDJD95tNn6LvYew4+Xbk1RD4k7UzWJS9AMobOK778NLNxfQ+Kn7MKzBHilXnSIVY5V+dcsOOdfqJviW4yWmT73JHYKq1qJip7Cw7lbkmRMUmettUwdVFWxeXH6iTex3YXCgqoriCx/MzeQhdNEycipooB/vHItRt1CF44uFWj9tf8n3TdbdH4dNMD0hw8ejHJSbEHb9HAGCugUniN8BzL9wxE959JU4cu3BKjDuIk5oS9hLR1mSc3vKBuSa3VKOE=\"}";

Map<String, List<String>> map = new HashMap<>();
map.put(Constants.X_LARK_REQUEST_TIMESTAMP.toLowerCase(), Arrays.asList("timestamp"));
map.put(Constants.X_LARK_REQUEST_NONCE.toLowerCase(), Arrays.asList("nonce"));
String signature = eventDispatcher.calculateSignature("timestamp", "nonce", "1212121212", body);
map.put(Constants.X_LARK_SIGNATURE.toLowerCase(), Arrays.asList(signature));

EventReq req = new EventReq();
req.setHeaders(map);
req.setBody(body.getBytes(StandardCharsets.UTF_8));

EventResp resp = eventDispatcher.handle(req);
assert resp != null;

}
}