Skip to content

Commit

Permalink
Merge pull request #100 from xmtp/xmtpnodejs
Browse files Browse the repository at this point in the history
xmtp-node-js-tools
  • Loading branch information
fabriguespe authored Dec 11, 2023
2 parents 0822a68 + 5c22bfc commit 6cd4a63
Show file tree
Hide file tree
Showing 45 changed files with 3,297 additions and 1,754 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Yarn v3
run: |
corepack enable
corepack prepare [email protected]-rc.51 --activate
corepack prepare [email protected] --activate
- run: yarn
- run: yarn build
- run: yarn lint
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Install Yarn v3
run: |
corepack enable
corepack prepare [email protected]-rc.51 --activate
corepack prepare [email protected] --activate
- name: Install dependencies
run: yarn
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Install Yarn v3
- name: Install Yarn v4
run: |
corepack enable
corepack prepare [email protected]-rc.51 --activate
corepack prepare [email protected] --activate
- run: yarn
- run: yarn build
- run: yarn workspace @xmtp/bot-kit-pro run up
Expand Down
52 changes: 10 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ A common complaint from developers using XMTP to build bots is the high cost of

No more poring over server logs. Because every incoming and outgoing message is stored in a database, you can build admin pages using tools like Retool to view the history of your bot's replies.

### 🧑🏻‍💻 CLI Starter

Starter project for building an XMTP CLI. It provides a basic setup and examples to get started with building a command-line interface for XMTP.

### Bot Starter

This repo makes it easier to create a bot on the XMTP network. It provides a basic setup and examples to get started with bot creation

## Packages

This repo contains the following packages
Expand All @@ -30,45 +38,5 @@ This repo contains the following packages
- [GRPC API CLient](./packages/grpc-api-client/README.md)
- [Redis Persistence](./packages/redis-persistence/README.md)
- [Bot Examples](./packages/bot-examples/)

## Usage

Let's create a simple bot that uses both the `botState` and `conversationState` to keep track of a waitlist for an event.

```ts
import { HandlerContext, newBotConfig, run } from "@xmtp/bot-kit-pro"

type BotState = {
waitListLength?: number
}

type ConvoState = {
isOnWaitlist?: boolean
}
/**
* A simple bot that adds each user to a waitlist and keeps track of how many members are ahead of them
*/
function waitlist(ctx: HandlerContext<ConvoState, BotState>) {
// Check the conversation state to see if the user has already been added
if (ctx.conversationState.isOnWaitlist) {
return ctx.reply("You're already on the waitlist!")
}
// Increment the waitListLength variable for the new member
ctx.botState.waitListLength = (ctx.botState.waitListLength || 0) + 1

ctx.conversationState.isOnWaitlist = true
// Send a reply
ctx.reply(
`You are on the waitlist in position ${ctx.botState.waitListLength}`,
)
}

const config = newBotConfig(
"waitlist",
{
xmtpKeys: process.env.XMTP_KEYS,
xmtpEnv: "dev",
},
waitlist,
)
```
- [Bot Starter](./packages/bot-starter/)
- [CLI Starter](./packages/cli-starter/)
2 changes: 1 addition & 1 deletion dev/docker/examples.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:18

RUN corepack enable && corepack prepare [email protected]-rc.51 --activate
RUN corepack enable && corepack prepare [email protected] --activate

COPY . /app/
WORKDIR /app
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"build": "turbo run build",
"publish": "yarn build && changeset publish",
"release": "yarn workspaces foreach --no-private --all npm publish --access public --tolerate-republish && changeset tag",
"test": "turbo run test"
"test": "turbo run test",
"fresh": "find . -name 'node_modules' -type d -exec rm -rf {} + && find . -name 'dist' -type d -exec rm -rf {} + && yarn cache clean && yarn install && yarn build && yarn test --scope=@xmtp/bot-kit-pro && yarn test --scope=@xmtp/redis-persistence && yarn test --scope=@xmtp/bot-starter && yarn test --scope=@xmtp/bot-examples && yarn test --scope=@xmtp/grpc-api-client && yarn test --scope=@xmtp/fs-persistence && yarn test --scope=@xmtp/cli-starter ",
"fresh2": "find . -name 'node_modules' -type d -exec rm -rf {} + && find . -name 'dist' -type d -exec rm -rf {} + && yarn cache clean && yarn install && yarn build --scope=@xmtp/cli-starter && yarn test --scope=@xmtp/cli-starter"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -58,5 +60,5 @@
"typescript": "~5.2.2",
"vitest": "^0.34.6"
},
"packageManager": "[email protected]-rc.51"
"packageManager": "[email protected]"
}
Loading

0 comments on commit 6cd4a63

Please sign in to comment.