Skip to content

Commit

Permalink
feat: rewrite plugin to v2 (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf authored Oct 29, 2024
1 parent 9725eca commit f204003
Show file tree
Hide file tree
Showing 25 changed files with 5,727 additions and 3,456 deletions.
144 changes: 72 additions & 72 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,77 +9,77 @@
name: grammY conversations

on:
push:
branches: [main]
pull_request:
branches: [main]
push:
branches: [main]
pull_request:
branches: [main]

jobs:
backport:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v3

- name: Install dependencies
run: npm install --ignore-scripts

- name: Run backporting
run: npm run backport

format-and-lint:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v3

- uses: denoland/setup-deno@main
with:
deno-version: v1.x

- name: Check Format
run: deno fmt --check

- name: Lint
run: deno lint

test:
runs-on: ${{ matrix.os }} # runs a test on Ubuntu, Windows and macOS

strategy:
matrix:
os: [macOS-latest, windows-latest, ubuntu-latest]

steps:
- name: Setup repo
uses: actions/checkout@v3

- uses: denoland/setup-deno@main
with:
deno-version: v1.x

- name: Cache Dependencies
run: deno cache src/mod.ts

- name: Run Tests
run: deno task test

coverage:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: denoland/setup-deno@main
with:
deno-version: v1.x

- name: Create coverage files
run: deno task coverage

- name: Collect coverage
uses: codecov/[email protected] # upload the report on Codecov
with:
file: ./coverage.lcov
backport:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Install dependencies
run: npm install --ignore-scripts

- name: Run backporting
run: npm run backport

format-and-lint:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v4

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Check Format
run: deno fmt --check

- name: Lint
run: deno lint

test:
runs-on: ${{ matrix.os }} # runs a test on Ubuntu, Windows and macOS

strategy:
matrix:
os: [macOS-latest, windows-latest, ubuntu-latest]

steps:
- name: Setup repo
uses: actions/checkout@v4

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Cache Dependencies
run: deno task check

- name: Run Tests
run: deno task test

coverage:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Create coverage files
run: deno task coverage

- name: Collect coverage
uses: codecov/[email protected] # upload the report on Codecov
with:
file: ./coverage.lcov
9 changes: 0 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,5 @@
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"deno.enable": true,
"deno.lint": true,
"deno.config": "./deno.jsonc",
"deno.suggest.imports.hosts": {
"https://deno.land": true,
"https://x.nest.land": true,
"https://crux.land": true,
"https://lib.deno.dev": false
}
}
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
# <h1 align="center">grammY Conversations</h1>
# <h1 align="center">grammY conversations</h1>

---

The grammY conversations plugin lets you create powerful conversational interfaces with ease.

Here is a quickstart for you, but the real docs are on this page: <https://grammy.dev/plugins/conversations>
This is version 2 of the plugin.
Version 2 is a complete rewrite from scratch.
It is not released yet, but most of the coding is done, so it will likely be released in the coming days or weeks, right after the documentation was written.

That being said, now is the perfect time to try out the rewrite!

Here is a quickstart for you for v2, but if you want to use v1 instead, you should rather look at the actual docs page: <https://grammy.dev/plugins/conversations>

## Quickstart

Run `npm i grammy @grammyjs/conversations` and paste the following code:
Run `npm i github:grammyjs/conversations` to install the code right from this repository and paste the following code:

```ts
import { Bot, type Context, session } from "grammy";
import { Bot, type Context } from "grammy";
import {
type Conversation,
type ConversationFlavor,
conversations,
createConversation,
} from "@grammyjs/conversations";

type MyContext = Context & ConversationFlavor;
type MyConversation = Conversation<MyContext>;
type MyContext = ConversationFlavor<Context>;
type MyConversationContext = HydrateFlavor<Context>;

type MyConversation = Conversation<MyConversationContext>;

const bot = new Bot<MyContext>("");

/** Defines the conversation */
async function greeting(conversation: MyConversation, ctx: MyContext) {
async function greeting(
conversation: MyConversation,
ctx: MyConversationContext,
) {
await ctx.reply("Hi there! What is your name?");
const { message } = await conversation.wait();
await ctx.reply(`Welcome to the chat, ${message.text}!`);
}

bot.use(session({ initial: () => ({}) }));
bot.use(conversations());

bot.use(createConversation(greeting));

bot.command("enter", async (ctx) => {
Expand Down
29 changes: 11 additions & 18 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
{
"lock": false,
"tasks": {
"check": "deno cache --check=all src/mod.ts",
"backport": "deno run --no-prompt --allow-read=. --allow-write=. https://deno.land/x/[email protected]/src/cli.ts tsconfig.json",
"test": "deno test test",
"dev": "deno fmt && deno lint && deno task test && deno task check",
"check": "deno cache --allow-import --check=all src/mod.ts",
"build": "deno run --no-prompt --allow-read=. --allow-write=. https://deno.land/x/[email protected]/src/cli.ts tsconfig.json",
"test": "deno test --allow-import test",
"ok": "deno fmt && deno lint && deno task test && deno task check",
"clean": "git clean -fX out test/cov_profile test/coverage coverage.lcov",
"coverage": "deno task clean && deno task test --coverage=./test/cov_profile && deno coverage --lcov --output=./coverage.lcov ./test/cov_profile",
"report": "genhtml ./coverage.lcov --output-directory ./test/coverage/ && echo 'Point your browser to test/coverage/index.html to see the test coverage report.'"
},
"exclude": [
"./node_modules/",
"./out/",
"./package-lock.json",
"./test/cov_profile"
],
"fmt": {
"indentWidth": 4,
"proseWrap": "preserve",
"exclude": [
"./node_modules/",
"./out/",
"./package-lock.json",
"./test/cov_profile"
]
},
"lint": {
"exclude": [
"./node_modules/",
"./out/",
"./package-lock.json"
]
"proseWrap": "preserve"
}
}
Loading

0 comments on commit f204003

Please sign in to comment.