Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ await textbee.setDefaultDevice(deviceId)
```js
// Paginated history, filterable and searchable
const { data, meta } = await textbee.getMessages(deviceId, {
type: 'received', // 'all' | 'sent' | 'received'
type: 'received', // filter is lowercase: 'all' | 'sent' | 'received'
page: 1,
limit: 50,
search: 'invoice',
})

// Each message reports its direction uppercase, so compare accordingly
data.filter((m) => m.type === 'RECEIVED')

// A single message and its current status
const sms = await textbee.getSms(deviceId, smsId)

Expand Down Expand Up @@ -137,7 +140,7 @@ new Textbee({

## What is not covered yet

v0.0.1 focuses on sending and reading messages. Bulk send and a few device operations are still REST only, documented at [textbee.dev/docs](https://textbee.dev/docs).
The SDK focuses on sending and reading messages. Bulk send and a few device operations are still REST only, documented at [textbee.dev/docs](https://textbee.dev/docs).

## License

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@textbee/sdk",
"version": "0.0.2",
"version": "0.0.3",
"description": "Official JavaScript SDK for textbee.dev, the open source SMS gateway",
"license": "MIT",
"packageManager": "pnpm@9.14.2",
Expand Down
9 changes: 7 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,13 @@ export interface Device {
export interface Message {
_id: string
message: string
type: 'sent' | 'received'
status:
/**
* Direction, uppercase. Note the asymmetry with the `type` filter accepted by
* getMessages, which is lowercase.
*/
type: 'SENT' | 'RECEIVED'
/** Lowercase, and absent on messages stored before status tracking. */
status?:
| 'pending'
| 'dispatched'
| 'sent'
Expand Down
4 changes: 3 additions & 1 deletion test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ describe('telemetry headers', () => {

describe('response envelopes', () => {
it('returns getMessages as { data, meta } because it has no outer wrapper', async () => {
// The response carries the direction uppercase while the query filter
// below stays lowercase. That asymmetry is the API's, not a typo here.
const page = {
data: [{ _id: 'sms-1', message: 'hi', type: 'received', status: 'received' }],
data: [{ _id: 'sms-1', message: 'hi', type: 'RECEIVED', status: 'received' }],
meta: { page: 2, limit: 10, total: 11, totalPages: 2 },
}
fetchMock.mockImplementation(async () => respond(200, page))
Expand Down