@beeperbot/sdk 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +239 -100
- package/dist/index.cjs +217 -182
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +789 -774
- package/dist/index.d.ts +789 -774
- package/dist/index.js +218 -181
- package/dist/index.js.map +1 -1
- package/package.json +71 -57
package/README.md
CHANGED
|
@@ -1,177 +1,316 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @beeper/sdk
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for [beep.works](https://beep.works) — the attention
|
|
3
|
+
TypeScript SDK for [beep.works](https://beep.works) — the attention layer on Base.
|
|
4
4
|
|
|
5
|
-
Send
|
|
5
|
+
Send paid messages (beeps) to Farcaster users. Look up users, check prices, run targeted campaigns.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @
|
|
10
|
+
npm install @beeper/sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
## Quick Start
|
|
13
|
+
## Quick Start — AI Agent
|
|
14
|
+
|
|
15
|
+
The `AgentClient` is the simplest way to integrate beeps into your AI agent or bot.
|
|
14
16
|
|
|
15
17
|
```typescript
|
|
16
|
-
import { AgentClient } from '@
|
|
18
|
+
import { AgentClient } from '@beeper/sdk';
|
|
17
19
|
|
|
18
|
-
const
|
|
19
|
-
apiKey:
|
|
20
|
-
environment: 'production',
|
|
20
|
+
const agent = new AgentClient({
|
|
21
|
+
apiKey: process.env.BEEPER_API_KEY!, // bpk_live_...
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
// Look up a user
|
|
24
|
-
const user = await
|
|
25
|
-
console.log(user
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const intent = await client.createIntent({
|
|
33
|
-
to: 'dwr',
|
|
34
|
-
amountUsd: 1.0,
|
|
35
|
-
message: 'Hey, check this out!',
|
|
25
|
+
const user = await agent.lookup('dwr.eth');
|
|
26
|
+
console.log(`@${user.username} — min beep price: $${user.attentionPriceUsd}`);
|
|
27
|
+
|
|
28
|
+
// Create a payment intent
|
|
29
|
+
const intent = await agent.createIntent({
|
|
30
|
+
to: 'dwr.eth',
|
|
31
|
+
amount: '$5',
|
|
32
|
+
message: 'Love your work on Farcaster!',
|
|
36
33
|
});
|
|
37
|
-
console.log(intent);
|
|
34
|
+
console.log(intent.instruction);
|
|
35
|
+
// → "Send 5.50 USDC to 0x1a2b... on Base ($5.00 to @dwr + $0.50 platform fee)"
|
|
38
36
|
```
|
|
39
37
|
|
|
40
|
-
##
|
|
38
|
+
## API Reference — AgentClient
|
|
39
|
+
|
|
40
|
+
### `new AgentClient(config)`
|
|
41
|
+
|
|
42
|
+
| Option | Type | Default | Description |
|
|
43
|
+
|--------|------|---------|-------------|
|
|
44
|
+
| `apiKey` | `string` | *required* | API key (`bpk_live_...` or `bpk_test_...`) |
|
|
45
|
+
| `environment` | `'production' \| 'staging'` | `'production'` | API environment |
|
|
46
|
+
| `baseUrl` | `string` | auto | Custom API base URL |
|
|
47
|
+
| `timeoutMs` | `number` | `30000` | Request timeout |
|
|
48
|
+
| `debug` | `boolean` | `false` | Enable debug logging |
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
---
|
|
43
51
|
|
|
44
|
-
### `lookup(
|
|
45
|
-
|
|
52
|
+
### `agent.lookup(identifier)`
|
|
53
|
+
|
|
54
|
+
Look up a user by username, FID, or wallet address.
|
|
46
55
|
|
|
47
56
|
```typescript
|
|
48
|
-
const user = await
|
|
49
|
-
const user = await
|
|
50
|
-
const user = await
|
|
57
|
+
const user = await agent.lookup('dwr.eth'); // by username
|
|
58
|
+
const user = await agent.lookup(3); // by FID
|
|
59
|
+
const user = await agent.lookup('0x1a2b...'); // by wallet
|
|
51
60
|
```
|
|
52
61
|
|
|
53
|
-
|
|
62
|
+
**Returns:** `User`
|
|
63
|
+
|
|
64
|
+
| Field | Type | Description |
|
|
65
|
+
|-------|------|-------------|
|
|
66
|
+
| `id` | `string` | Internal user ID |
|
|
67
|
+
| `fid` | `number?` | Farcaster ID |
|
|
68
|
+
| `username` | `string` | Username |
|
|
69
|
+
| `displayName` | `string?` | Display name |
|
|
70
|
+
| `pfpUrl` | `string?` | Profile picture URL |
|
|
71
|
+
| `platform` | `string` | Platform (farcaster, twitter) |
|
|
72
|
+
| `walletAddress` | `string?` | Verified wallet address |
|
|
73
|
+
| `attentionPriceUsd` | `string` | Minimum beep price in USD |
|
|
74
|
+
| `followerCount` | `number?` | Follower count |
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### `agent.getPrice(identifier)`
|
|
79
|
+
|
|
54
80
|
Get the attention price for a user.
|
|
55
81
|
|
|
56
82
|
```typescript
|
|
57
|
-
const price = await
|
|
58
|
-
|
|
83
|
+
const price = await agent.getPrice('dwr.eth');
|
|
84
|
+
console.log(`$${price.priceUsd} USD`);
|
|
59
85
|
```
|
|
60
86
|
|
|
61
|
-
|
|
62
|
-
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### `agent.createIntent(input)`
|
|
90
|
+
|
|
91
|
+
Create a payment intent. Returns instructions for the user to execute the payment.
|
|
63
92
|
|
|
64
93
|
```typescript
|
|
65
|
-
const intent = await
|
|
66
|
-
to: 'dwr',
|
|
67
|
-
|
|
68
|
-
message: 'Hello!', //
|
|
69
|
-
chainId: 8453,
|
|
94
|
+
const intent = await agent.createIntent({
|
|
95
|
+
to: 'dwr.eth', // recipient
|
|
96
|
+
amount: '$5', // amount in USD
|
|
97
|
+
message: 'Hello!', // required message
|
|
98
|
+
chainId: 8453, // Base (default)
|
|
70
99
|
});
|
|
71
100
|
```
|
|
72
101
|
|
|
73
|
-
|
|
74
|
-
|
|
102
|
+
**Returns:** `PaymentIntent` with `intentId`, `recipient`, `amount`, `instruction`, fee breakdown, etc.
|
|
103
|
+
|
|
104
|
+
> **Note:** A 10% platform fee is added on top. `$5` beep → user pays `$5.50` USDC total.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
### `agent.estimate(input)`
|
|
109
|
+
|
|
110
|
+
Estimate how many recipients you can reach within a budget.
|
|
75
111
|
|
|
76
112
|
```typescript
|
|
77
|
-
const estimate = await
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
113
|
+
const estimate = await agent.estimate({
|
|
114
|
+
filters: {
|
|
115
|
+
platform: 'farcaster',
|
|
116
|
+
neynarScoreMin: 0.5,
|
|
117
|
+
minFollowers: 1000,
|
|
118
|
+
countries: ['US'],
|
|
119
|
+
},
|
|
120
|
+
budget: '$100',
|
|
81
121
|
});
|
|
82
|
-
|
|
122
|
+
|
|
123
|
+
console.log(`Can reach ${estimate.recipientCount} people`);
|
|
124
|
+
console.log(`Total cost: $${estimate.totalCostUsd}`);
|
|
125
|
+
console.log(`Budget sufficient: ${estimate.budgetSufficient}`);
|
|
83
126
|
```
|
|
84
127
|
|
|
85
|
-
|
|
86
|
-
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### `agent.preview(input)`
|
|
131
|
+
|
|
132
|
+
Preview sample users matching your filters.
|
|
87
133
|
|
|
88
134
|
```typescript
|
|
89
|
-
const preview = await
|
|
90
|
-
|
|
91
|
-
limit:
|
|
135
|
+
const preview = await agent.preview({
|
|
136
|
+
filters: { neynarScoreMin: 0.7, hasBaseWallet: true },
|
|
137
|
+
limit: 5,
|
|
92
138
|
});
|
|
93
|
-
|
|
139
|
+
|
|
140
|
+
preview.users.forEach(u => {
|
|
141
|
+
console.log(`@${u.username} — $${u.priceUsd} — ${u.followerCount} followers`);
|
|
142
|
+
});
|
|
143
|
+
console.log(`Total matching: ${preview.totalCount}`);
|
|
94
144
|
```
|
|
95
145
|
|
|
96
|
-
|
|
97
|
-
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
### `agent.createBulkIntent(input)`
|
|
149
|
+
|
|
150
|
+
Create payment intents for multiple recipients matching filters.
|
|
98
151
|
|
|
99
152
|
```typescript
|
|
100
|
-
const bulk = await
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
message: 'GM
|
|
153
|
+
const bulk = await agent.createBulkIntent({
|
|
154
|
+
filters: { signalTokens: ['0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'] },
|
|
155
|
+
budget: '$50',
|
|
156
|
+
message: 'GM DEGEN community! 🎩',
|
|
104
157
|
});
|
|
105
|
-
// { intentId, recipientCount, totalAmountUsd, ... }
|
|
106
|
-
```
|
|
107
158
|
|
|
108
|
-
|
|
159
|
+
console.log(bulk.summary);
|
|
160
|
+
// → "Send to 120 recipients for total 42.50 USDC on Base"
|
|
161
|
+
```
|
|
109
162
|
|
|
110
|
-
|
|
163
|
+
---
|
|
111
164
|
|
|
112
|
-
|
|
113
|
-
import { BeeperClient } from '@beeperbot/sdk';
|
|
165
|
+
### `agent.describeFilters()`
|
|
114
166
|
|
|
115
|
-
|
|
116
|
-
apiKey: 'bpk_live_...',
|
|
117
|
-
});
|
|
167
|
+
Get structured filter documentation for LLM system prompts.
|
|
118
168
|
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
const confirmed = await beeper.confirmDeposit(quote.id, { txHash: '0x...' });
|
|
123
|
-
const result = await beeper.execute(quote.id);
|
|
124
|
-
const receipt = await beeper.getReceipt(quote.id);
|
|
169
|
+
```typescript
|
|
170
|
+
const schema = agent.describeFilters();
|
|
171
|
+
// Use in your LLM's system prompt for filter-aware conversations
|
|
125
172
|
```
|
|
126
173
|
|
|
127
|
-
|
|
174
|
+
### `agent.getFilterDocumentation()`
|
|
128
175
|
|
|
129
|
-
|
|
176
|
+
Get markdown-formatted filter docs.
|
|
130
177
|
|
|
131
178
|
```typescript
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const filter = FilterBuilder.and(
|
|
135
|
-
FilterBuilder.platform('farcaster'),
|
|
136
|
-
FilterBuilder.minFollowers(1000),
|
|
137
|
-
FilterBuilder.neynarScoreMin(0.8),
|
|
138
|
-
FilterBuilder.maxAttentionPrice(2.0),
|
|
139
|
-
);
|
|
179
|
+
const docs = agent.getFilterDocumentation();
|
|
180
|
+
// Include in system prompt: `Available filters:\n${docs}`
|
|
140
181
|
```
|
|
141
182
|
|
|
142
|
-
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Filters Reference
|
|
186
|
+
|
|
187
|
+
Use filters with `estimate`, `preview`, and `createBulkIntent`.
|
|
188
|
+
|
|
189
|
+
### Platform & Activity
|
|
190
|
+
| Filter | Type | Description |
|
|
191
|
+
|--------|------|-------------|
|
|
192
|
+
| `platform` | `'all' \| 'farcaster' \| 'twitter'` | Target platform |
|
|
193
|
+
| `activeInLastDays` | `number` | Users active within N days |
|
|
194
|
+
|
|
195
|
+
### Reputation & Quality
|
|
196
|
+
| Filter | Type | Description |
|
|
197
|
+
|--------|------|-------------|
|
|
198
|
+
| `neynarScoreMin` | `number (0-1)` | Min Neynar reputation. 0.5+ = quality, 0.8+ = top tier |
|
|
199
|
+
| `neynarScoreMax` | `number (0-1)` | Max Neynar reputation |
|
|
200
|
+
| `quotientScoreMin` | `number (0-1)` | Min Quotient engagement score |
|
|
201
|
+
| `quotientScoreMax` | `number (0-1)` | Max Quotient score |
|
|
202
|
+
| `spamLabel` | `'not_spam_only' \| 'spam_only' \| 'all'` | Spam classification |
|
|
203
|
+
| `verifiedOnly` | `boolean` | Only wallet-verified users |
|
|
204
|
+
|
|
205
|
+
### Social Graph
|
|
206
|
+
| Filter | Type | Description |
|
|
207
|
+
|--------|------|-------------|
|
|
208
|
+
| `minFollowers` | `number` | Minimum follower count |
|
|
209
|
+
| `maxFollowers` | `number` | Maximum follower count |
|
|
210
|
+
|
|
211
|
+
### Token Filters
|
|
212
|
+
| Filter | Type | Description |
|
|
213
|
+
|--------|------|-------------|
|
|
214
|
+
| `signalTokens` | `string[]` | Token addresses users set as interests (community affinity) |
|
|
215
|
+
| `tokenHolders` | `Array<{tokenAddress, chainId, minBalance?}>` | Actual onchain token holders |
|
|
216
|
+
| `hasBaseWallet` | `boolean` | Has a Base chain wallet |
|
|
217
|
+
| `hasVerifiedWallet` | `boolean` | Has a verified wallet |
|
|
218
|
+
|
|
219
|
+
### Economics
|
|
220
|
+
| Filter | Type | Description |
|
|
221
|
+
|--------|------|-------------|
|
|
222
|
+
| `maxAttentionPriceUsd` | `number` | Max beep price cap |
|
|
223
|
+
| `minBatteryPercentage` | `number (0-100)` | Min battery (engagement metric) |
|
|
224
|
+
| `hasRechargedInLastDays` | `number` | Checked in within N days |
|
|
225
|
+
| `excludePingedToday` | `boolean` | Skip users already beeped today |
|
|
226
|
+
|
|
227
|
+
### Geography
|
|
228
|
+
| Filter | Type | Description |
|
|
229
|
+
|--------|------|-------------|
|
|
230
|
+
| `countries` | `string[]` | ISO 3166-1 alpha-2 codes (`['US', 'KR']`) |
|
|
231
|
+
|
|
232
|
+
### Sorting
|
|
233
|
+
| Value | Description |
|
|
234
|
+
|-------|-------------|
|
|
235
|
+
| `attention_price_asc` | Cheapest first (maximize reach) |
|
|
236
|
+
| `attention_price_desc` | Most expensive first |
|
|
237
|
+
| `neynar_score_desc` | Highest reputation first |
|
|
238
|
+
| `followers_desc` | Most followers first |
|
|
239
|
+
| `recent_activity` | Most recently active |
|
|
240
|
+
| `battery_desc` | Highest engagement first |
|
|
241
|
+
| `random` | Random order |
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Advanced — BeeperClient
|
|
246
|
+
|
|
247
|
+
For the full deposit → execute → receipt flow:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
import { BeeperClient } from '@beeper/sdk';
|
|
251
|
+
|
|
252
|
+
const client = new BeeperClient({
|
|
253
|
+
apiKey: process.env.BEEPER_API_KEY!,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// 1. Create a draft (local, no API call)
|
|
257
|
+
const draft = client.createDraft({
|
|
258
|
+
filter: { and: [
|
|
259
|
+
{ field: 'neynarScore', op: 'gte', value: 0.5 },
|
|
260
|
+
{ field: 'hasBaseWallet', op: 'eq', value: true },
|
|
261
|
+
]},
|
|
262
|
+
tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
|
|
263
|
+
chainId: 8453, // Base
|
|
264
|
+
amountPerRecipient: '1000000', // 1 USDC (6 decimals)
|
|
265
|
+
budgetCap: '100000000', // 100 USDC max
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// 2. Get a quote
|
|
269
|
+
const quote = await client.createQuote(draft);
|
|
143
270
|
|
|
144
|
-
|
|
271
|
+
// 3. Deposit tokens to quote.depositAddress
|
|
272
|
+
// 4. Confirm deposit
|
|
273
|
+
await client.confirmDeposit(quote.id, { txHash: '0x...' });
|
|
145
274
|
|
|
146
|
-
|
|
275
|
+
// 5. Execute
|
|
276
|
+
await client.executeSend(quote.id);
|
|
277
|
+
|
|
278
|
+
// 6. Poll for completion
|
|
279
|
+
const receipt = await client.pollUntilCompleteByQuoteId(quote.id);
|
|
280
|
+
```
|
|
147
281
|
|
|
148
282
|
## Error Handling
|
|
149
283
|
|
|
150
284
|
```typescript
|
|
151
|
-
import { BeeperError } from '@
|
|
285
|
+
import { BeeperError, ErrorCodes } from '@beeper/sdk';
|
|
152
286
|
|
|
153
287
|
try {
|
|
154
|
-
|
|
288
|
+
await agent.lookup('nonexistent');
|
|
155
289
|
} catch (err) {
|
|
156
290
|
if (err instanceof BeeperError) {
|
|
157
291
|
console.log(err.code); // 'NOT_FOUND'
|
|
158
|
-
console.log(err.message); //
|
|
159
|
-
console.log(err.status); //
|
|
292
|
+
console.log(err.message); // Human-readable message
|
|
293
|
+
console.log(err.status); // HTTP status code
|
|
160
294
|
}
|
|
161
295
|
}
|
|
162
296
|
```
|
|
163
297
|
|
|
164
|
-
|
|
298
|
+
Retryable errors: `RATE_LIMITED`, `SERVER_ERROR`, `TIMEOUT`. Use exponential backoff.
|
|
165
299
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
300
|
+
## API Keys
|
|
301
|
+
|
|
302
|
+
Get your API key at [beep.works/sdk](https://beep.works/sdk).
|
|
303
|
+
|
|
304
|
+
- `bpk_live_...` — Production
|
|
305
|
+
- `bpk_test_...` — Sandbox (no real transactions)
|
|
306
|
+
|
|
307
|
+
**Never expose API keys in frontend code.** Use server-side only.
|
|
308
|
+
|
|
309
|
+
## Links
|
|
310
|
+
|
|
311
|
+
- [beep.works](https://beep.works) — Main app
|
|
312
|
+
- [API Docs](https://docs.beep.works) — Full API reference
|
|
313
|
+
- [Discord](https://discord.gg/beepworks) — Community & support
|
|
175
314
|
|
|
176
315
|
## License
|
|
177
316
|
|