@beeperbot/sdk 0.1.0 → 0.2.0

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 ADDED
@@ -0,0 +1,317 @@
1
+ # @beeper/sdk
2
+
3
+ TypeScript SDK for [beep.works](https://beep.works) — the attention layer on Base.
4
+
5
+ Send paid messages (beeps) to Farcaster users. Look up users, check prices, run targeted campaigns.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @beeper/sdk
11
+ ```
12
+
13
+ ## Quick Start — AI Agent
14
+
15
+ The `AgentClient` is the simplest way to integrate beeps into your AI agent or bot.
16
+
17
+ ```typescript
18
+ import { AgentClient } from '@beeper/sdk';
19
+
20
+ const agent = new AgentClient({
21
+ apiKey: process.env.BEEPER_API_KEY!, // bpk_live_...
22
+ });
23
+
24
+ // Look up a user
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!',
33
+ });
34
+ console.log(intent.instruction);
35
+ // → "Send 5.50 USDC to 0x1a2b... on Base ($5.00 to @dwr + $0.50 platform fee)"
36
+ ```
37
+
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 |
49
+
50
+ ---
51
+
52
+ ### `agent.lookup(identifier)`
53
+
54
+ Look up a user by username, FID, or wallet address.
55
+
56
+ ```typescript
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
60
+ ```
61
+
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
+
80
+ Get the attention price for a user.
81
+
82
+ ```typescript
83
+ const price = await agent.getPrice('dwr.eth');
84
+ console.log(`$${price.priceUsd} USD`);
85
+ ```
86
+
87
+ ---
88
+
89
+ ### `agent.createIntent(input)`
90
+
91
+ Create a payment intent. Returns instructions for the user to execute the payment.
92
+
93
+ ```typescript
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)
99
+ });
100
+ ```
101
+
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.
111
+
112
+ ```typescript
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',
121
+ });
122
+
123
+ console.log(`Can reach ${estimate.recipientCount} people`);
124
+ console.log(`Total cost: $${estimate.totalCostUsd}`);
125
+ console.log(`Budget sufficient: ${estimate.budgetSufficient}`);
126
+ ```
127
+
128
+ ---
129
+
130
+ ### `agent.preview(input)`
131
+
132
+ Preview sample users matching your filters.
133
+
134
+ ```typescript
135
+ const preview = await agent.preview({
136
+ filters: { neynarScoreMin: 0.7, hasBaseWallet: true },
137
+ limit: 5,
138
+ });
139
+
140
+ preview.users.forEach(u => {
141
+ console.log(`@${u.username} — $${u.priceUsd} — ${u.followerCount} followers`);
142
+ });
143
+ console.log(`Total matching: ${preview.totalCount}`);
144
+ ```
145
+
146
+ ---
147
+
148
+ ### `agent.createBulkIntent(input)`
149
+
150
+ Create payment intents for multiple recipients matching filters.
151
+
152
+ ```typescript
153
+ const bulk = await agent.createBulkIntent({
154
+ filters: { signalTokens: ['0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed'] },
155
+ budget: '$50',
156
+ message: 'GM DEGEN community! 🎩',
157
+ });
158
+
159
+ console.log(bulk.summary);
160
+ // → "Send to 120 recipients for total 42.50 USDC on Base"
161
+ ```
162
+
163
+ ---
164
+
165
+ ### `agent.describeFilters()`
166
+
167
+ Get structured filter documentation for LLM system prompts.
168
+
169
+ ```typescript
170
+ const schema = agent.describeFilters();
171
+ // Use in your LLM's system prompt for filter-aware conversations
172
+ ```
173
+
174
+ ### `agent.getFilterDocumentation()`
175
+
176
+ Get markdown-formatted filter docs.
177
+
178
+ ```typescript
179
+ const docs = agent.getFilterDocumentation();
180
+ // Include in system prompt: `Available filters:\n${docs}`
181
+ ```
182
+
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);
270
+
271
+ // 3. Deposit tokens to quote.depositAddress
272
+ // 4. Confirm deposit
273
+ await client.confirmDeposit(quote.id, { txHash: '0x...' });
274
+
275
+ // 5. Execute
276
+ await client.executeSend(quote.id);
277
+
278
+ // 6. Poll for completion
279
+ const receipt = await client.pollUntilCompleteByQuoteId(quote.id);
280
+ ```
281
+
282
+ ## Error Handling
283
+
284
+ ```typescript
285
+ import { BeeperError, ErrorCodes } from '@beeper/sdk';
286
+
287
+ try {
288
+ await agent.lookup('nonexistent');
289
+ } catch (err) {
290
+ if (err instanceof BeeperError) {
291
+ console.log(err.code); // 'NOT_FOUND'
292
+ console.log(err.message); // Human-readable message
293
+ console.log(err.status); // HTTP status code
294
+ }
295
+ }
296
+ ```
297
+
298
+ Retryable errors: `RATE_LIMITED`, `SERVER_ERROR`, `TIMEOUT`. Use exponential backoff.
299
+
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
314
+
315
+ ## License
316
+
317
+ MIT