From 0a3a7ccebd7200b2d97f4d9805c89a5e95c71811 Mon Sep 17 00:00:00 2001 From: Yevhen Denesiuk Date: Mon, 18 Oct 2021 15:37:33 +0300 Subject: [PATCH] Add framework adapters (#62) --- .all-contributorsrc | 7 +++++-- CONTRIBUTING.md | 6 +++--- README.md | 4 ++-- src/convenience/webhook.ts | 18 +++++++++++++++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index ffd93b0c..79e3df1f 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -81,7 +81,8 @@ "plugin", "doc", "example", - "review" + "review", + "mentoring" ] }, { @@ -239,7 +240,9 @@ "avatar_url": "https://avatars.githubusercontent.com/u/4936805?v=4", "profile": "https://github.com/dzek69", "contributions": [ - "doc" + "doc", + "code", + "bug" ] }, { diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ff8b1e39..cd95aa14 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,8 +23,8 @@ It solves this problem substantially better by providing a Deno-aware wrapper of Hence, you can write a Deno project and directly compile it to JavaScript files that run under Node.js. In other words, working on grammY effectively means work on a Deno project. -We use Deno testing, Deno linting, and the [Deno extension](https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno) for VSCode. -You usual TypeScript tooling does not workβ€”and once you tried developing for Deno, you know that this is a good thing. +We use Deno testing, Deno linting, Deno formatting, and the [Deno extension](https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno) for VSCode. +Your usual TypeScript tooling does not workβ€”and once you tried developing for Deno and you have experienced how superior the development experience is, you will know why we are happy about our choice. > Note that not all plugins of grammY have to have the same setup: many of them only integrate with grammY itself, and hence can be written for Node and automatically ported to Deno via and similar services. @@ -42,7 +42,7 @@ There are several areas of contributions, and they have different ways to get yo There are both official plugins and third-party plugins. Our official plugins need to be of high quality (100 % TypeScript, ES6, Deno support, docs that are on par with grammY, semver, etc). Third-party plugins are independent and anyone can do them however they want. - If a third-party plugins was to be listed on the website, some docs would be nice. + If a third-party plugin was to be listed on the website, some docs would be nice. - **Storage adapters.** Please send a message to the [group chat](https://telegram.me/grammyjs) if you want to create an offical storage adapter for the [session plugin](https://grammy.dev/plugins/session.html). You will be granted all necessary permissions, and the repository will be listed [here](https://grammy.dev/plugins/session.html#official). diff --git a/README.md b/README.md index cb5696f7..616a8af9 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Wojciech Pawlik

πŸ€” πŸ‘€ πŸš‡ πŸ“¦
Alessandro Bertozzi

πŸ“–
trgwii

πŸ’» πŸ‘€ -
KnightNiwrem

πŸ’» πŸ› πŸ”Œ πŸ“– πŸ’‘ πŸ‘€ +
KnightNiwrem

πŸ’» πŸ› πŸ”Œ πŸ“– πŸ’‘ πŸ‘€ πŸ§‘β€πŸ«
Muthu Kumar

πŸ‘€ @@ -140,7 +140,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
deptyped

πŸ’‘ πŸ“– βœ… -
Jacek Nowacki

πŸ“– +
Jacek Nowacki

πŸ“– πŸ’» πŸ›
Outvi V

πŸ’»
Ikko Ashimine

πŸ“–
Yevhen Denesiuk

πŸ‘€ πŸ› diff --git a/src/convenience/webhook.ts b/src/convenience/webhook.ts index 7ecc71cf..5bcd973d 100644 --- a/src/convenience/webhook.ts +++ b/src/convenience/webhook.ts @@ -16,7 +16,9 @@ type SupportedFrameworks = | "koa" | "oak" | "fastify" - | "worktop"; + | "worktop" + | "callback" + | "aws-api-lambda"; /** * Abstraction over a request-response cycle, provding access to the update, as @@ -71,6 +73,7 @@ const frameworkAdapters: Record = { }), fastify: (req, reply) => ({ update: Promise.resolve(req.body), + end: () => reply.send({}), respond: (json) => reply.send(json), }), worktop: (req, res) => ({ @@ -78,6 +81,19 @@ const frameworkAdapters: Record = { end: () => res.end(), respond: (json) => res.send(200, json), }), + callback: (update, callback) => ({ + update: update, + respond: callback, + }), + "aws-api-lambda": (event, _context, callback) => ({ + update: JSON.parse(event.body), + end: () => callback(null, { statusCode: 200 }), + respond: (json) => + callback(null, { + statusCode: 200, + body: json + }), + }) // please open a PR if you want to add another };