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

feat: add custom adapter #48

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

UNICKCHENG
Copy link

add a common custom adapter and a NextJS adapter.

// pages/api/webhook.ts
import * as lark from '@larksuiteoapi/node-sdk';

const client = new lark.Client({
    appId: 'xxxxxxxxxxxxxxxxxxxxxxx',
    appSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    appType: lark.AppType.SelfBuild
});

const eventDispatcher = new lark.EventDispatcher({
    verificationToken: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    encryptKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
}).register({
    'im.message.receive_v1': async (data) => {
        const chatId = data.message.chat_id;

        const res = await client.im.message.create({
            params: {
                receive_id_type: 'chat_id',
            },
            data: {
                receive_id: chatId,
                content: JSON.stringify({text: 'hello world'}),
                msg_type: 'text'
            },
        });
        return res;
    }
});

export default async (req: NextApiRequest, res: NextApiResponse) => {
    await lark.adaptNextjs(eventDispatcher, {
        autoChallenge: true,
    })(req, res);   
};

// 方式 2: 使用 adaptCustom
// export default async (req: NextApiRequest, res: NextApiResponse) => {
//    const result = await lark.adaptCustom(eventDispatcher, {
//        autoChallenge: true,
//    })(req.headers, req.body);
//    res.end(result);
//};

Related issues: #46, #32

UNICKCHENG added 2 commits May 8, 2023 10:25
- add adapator for NextJS
- add adapator for custom

see larksuite#32, larksuite#46
@UNICKCHENG UNICKCHENG changed the title feat: add custom adapator feat: add custom adapater May 8, 2023
@UNICKCHENG UNICKCHENG changed the title feat: add custom adapater feat: add custom adapter May 8, 2023
@mazhe-nerd
Copy link
Collaborator

感谢同学提供pr。有没有可运行的demo嘞?我想本地跑跑看。

@UNICKCHENG
Copy link
Author

UNICKCHENG commented May 15, 2023

感谢同学提供pr。有没有可运行的demo嘞?我想本地跑跑看。

@mazhe-nerd 试一试?

https://github.com/UNICKCHENG/lark-node-sdk-template

@UNICKCHENG
Copy link
Author

@mazhe-nerd 嗨,这个 PR 是还有啥问题么?

@mazhe-nerd
Copy link
Collaborator

我拉下来刷了下next的文档,还在review哈,最近在处理其它高优的事情。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants