@digisglobal/omnivox-sdk 0.3.0 → 0.4.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 +208 -0
- package/package.json +5 -3
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# @digisglobal/omnivox-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for integrating your backend product with the Omnivox API.
|
|
4
|
+
|
|
5
|
+
Use this package from server-side application code to authenticate with an Omnivox tenant, work with contacts and conversations, and send or list messages through the tenant's configured channels.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @digisglobal/omnivox-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Other package managers work too:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @digisglobal/omnivox-sdk
|
|
17
|
+
yarn add @digisglobal/omnivox-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Prerequisites
|
|
21
|
+
|
|
22
|
+
Before writing code, get these values from your Omnivox tenant admin, Omnivox Console, or Omnivox support contact:
|
|
23
|
+
|
|
24
|
+
- Your Omnivox API base URL
|
|
25
|
+
- An Omnivox API key for your tenant
|
|
26
|
+
|
|
27
|
+
Use placeholders like this in local development:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
OMNIVOX_BASE_URL=https://api.example.com
|
|
31
|
+
OMNIVOX_API_KEY=ovx_live_xxxxxx
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Keep the API key on your server. Do not expose it in browser bundles, mobile apps, logs, or client-side configuration.
|
|
35
|
+
|
|
36
|
+
## Create a Client
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import {
|
|
40
|
+
createApiKeyTokenProvider,
|
|
41
|
+
createOmnivoxClient,
|
|
42
|
+
} from '@digisglobal/omnivox-sdk'
|
|
43
|
+
|
|
44
|
+
const baseUrl = process.env.OMNIVOX_BASE_URL
|
|
45
|
+
const apiKey = process.env.OMNIVOX_API_KEY
|
|
46
|
+
|
|
47
|
+
if (!baseUrl || !apiKey) {
|
|
48
|
+
throw new Error('OMNIVOX_BASE_URL and OMNIVOX_API_KEY are required')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const omnivox = createOmnivoxClient({
|
|
52
|
+
baseUrl,
|
|
53
|
+
tokenProvider: createApiKeyTokenProvider(apiKey),
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Verify Access
|
|
58
|
+
|
|
59
|
+
Start with `auth.me()` to confirm that the base URL and API key are valid:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const me = await omnivox.auth.me()
|
|
63
|
+
|
|
64
|
+
console.log(`Connected to Omnivox tenant: ${me.tenant.name}`)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
For API-key authentication, `me.agent` is `null` because the request is made as a tenant API key rather than a logged-in Console agent.
|
|
68
|
+
|
|
69
|
+
## Available Modules
|
|
70
|
+
|
|
71
|
+
The composed client exposes these modules:
|
|
72
|
+
|
|
73
|
+
- `auth` - current tenant and actor context
|
|
74
|
+
- `tenants` - tenant-scoped channels and API keys
|
|
75
|
+
- `agents` - tenant agents
|
|
76
|
+
- `channels` - WhatsApp and Email channel configuration
|
|
77
|
+
- `contacts` - contacts, identities, tags, and custom fields
|
|
78
|
+
- `conversations` - conversation lifecycle, assignment, and lobby pickup
|
|
79
|
+
- `messages` - send, list, fetch, and soft-delete messages
|
|
80
|
+
|
|
81
|
+
## Common Workflows
|
|
82
|
+
|
|
83
|
+
### Search Contacts
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
const contacts = await omnivox.contacts.search({
|
|
87
|
+
page: 1,
|
|
88
|
+
pageSize: 20,
|
|
89
|
+
q: 'alex',
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
for (const contact of contacts.data) {
|
|
93
|
+
console.log(contact.displayName)
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Create a Contact
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
const contact = await omnivox.contacts.create({
|
|
101
|
+
displayName: 'Alex Rivera',
|
|
102
|
+
identities: [
|
|
103
|
+
{
|
|
104
|
+
channel: 'EMAIL',
|
|
105
|
+
value: 'alex@example.com',
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
console.log(contact)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Create or Reopen a Conversation
|
|
114
|
+
|
|
115
|
+
Use `reopenOrCreate()` when your product needs an active conversation for a known contact identity. If an active conversation already exists for the contact identity and channel, Omnivox returns it; otherwise Omnivox creates a new one.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const conversation = await omnivox.conversations.reopenOrCreate({
|
|
119
|
+
contactIdentityId: 'contact_identity_id',
|
|
120
|
+
channelId: 'channel_id',
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
console.log(conversation)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Send a Message
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
const message = await omnivox.messages.send({
|
|
130
|
+
conversationId: 'conversation_id',
|
|
131
|
+
body: 'Hello from your product.',
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
console.log(message)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Iterate Through Paginated Results
|
|
138
|
+
|
|
139
|
+
List endpoints return `{ data, meta }`. Use `iteratePages()` when you need to collect every page.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { iteratePages } from '@digisglobal/omnivox-sdk'
|
|
143
|
+
|
|
144
|
+
const allContacts = await iteratePages(
|
|
145
|
+
(params) => omnivox.contacts.search(params),
|
|
146
|
+
{ page: 1, pageSize: 100 },
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
console.log(`Loaded ${allContacts.length} contacts`)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The SDK clamps `pageSize` to the API maximum of `100`.
|
|
153
|
+
|
|
154
|
+
## Error Handling
|
|
155
|
+
|
|
156
|
+
SDK methods throw `OmnivoxRequestError` for non-2xx API responses. The error includes the HTTP status and parsed response body.
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { OmnivoxRequestError } from '@digisglobal/omnivox-sdk'
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
await omnivox.auth.me()
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (error instanceof OmnivoxRequestError) {
|
|
165
|
+
console.error('Omnivox request failed', {
|
|
166
|
+
status: error.status,
|
|
167
|
+
body: error.body,
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
throw error
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Common statuses during onboarding:
|
|
176
|
+
|
|
177
|
+
- `401` - missing, invalid, or revoked API key
|
|
178
|
+
- `400` - request body or query parameter failed validation
|
|
179
|
+
- `404` - the requested resource does not exist in your tenant
|
|
180
|
+
- `422` - the requested operation is not allowed by the channel or conversation state
|
|
181
|
+
|
|
182
|
+
## Security Notes
|
|
183
|
+
|
|
184
|
+
- Treat Omnivox API keys as server-side secrets.
|
|
185
|
+
- Do not put API keys in frontend code, mobile apps, or public repositories.
|
|
186
|
+
- Store API keys in your backend secret manager or deployment environment variables.
|
|
187
|
+
- Rotate or revoke API keys through your Omnivox admin flow when they are no longer needed.
|
|
188
|
+
|
|
189
|
+
## Runtime Notes
|
|
190
|
+
|
|
191
|
+
- Node.js `>=22` is supported.
|
|
192
|
+
- The SDK uses the platform `fetch` API. Node.js 22 includes `fetch` globally.
|
|
193
|
+
- The package ships ESM, CommonJS, and TypeScript declarations.
|
|
194
|
+
- Browser session-cookie authentication exists for Omnivox Console-style applications, but backend API-key authentication is the recommended path for tenant product integrations.
|
|
195
|
+
|
|
196
|
+
## API Reference
|
|
197
|
+
|
|
198
|
+
For complete request and response schemas, open the API reference for your Omnivox environment:
|
|
199
|
+
|
|
200
|
+
```text
|
|
201
|
+
<OMNIVOX_BASE_URL>/docs
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
For example, if your base URL is `https://api.example.com`, the API reference is available at `https://api.example.com/docs`.
|
|
205
|
+
|
|
206
|
+
## Support
|
|
207
|
+
|
|
208
|
+
If you do not have a base URL, tenant, or API key, contact your Omnivox tenant admin, Omnivox account team, or Omnivox support contact.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digisglobal/omnivox-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
"./package.json": "./package.json"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
16
17
|
],
|
|
17
18
|
"publishConfig": {
|
|
18
|
-
"access": "public"
|
|
19
|
+
"access": "public",
|
|
20
|
+
"registry": "https://registry.npmjs.org"
|
|
19
21
|
},
|
|
20
22
|
"engines": {
|
|
21
23
|
"node": ">=22"
|