movoice 0.1.0__tar.gz
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.
- movoice-0.1.0/.gitignore +6 -0
- movoice-0.1.0/LICENSE +21 -0
- movoice-0.1.0/PKG-INFO +307 -0
- movoice-0.1.0/README.md +275 -0
- movoice-0.1.0/pyproject.toml +63 -0
- movoice-0.1.0/src/movoice/__init__.py +50 -0
- movoice-0.1.0/src/movoice/_client.py +108 -0
- movoice-0.1.0/src/movoice/_http.py +281 -0
- movoice-0.1.0/src/movoice/_version.py +1 -0
- movoice-0.1.0/src/movoice/errors.py +248 -0
- movoice-0.1.0/src/movoice/pagination.py +75 -0
- movoice-0.1.0/src/movoice/py.typed +0 -0
- movoice-0.1.0/src/movoice/resources/__init__.py +22 -0
- movoice-0.1.0/src/movoice/resources/_base.py +23 -0
- movoice-0.1.0/src/movoice/resources/account.py +18 -0
- movoice-0.1.0/src/movoice/resources/agents.py +135 -0
- movoice-0.1.0/src/movoice/resources/appointments.py +188 -0
- movoice-0.1.0/src/movoice/resources/calls.py +111 -0
- movoice-0.1.0/src/movoice/resources/contacts.py +62 -0
- movoice-0.1.0/src/movoice/resources/memory.py +29 -0
- movoice-0.1.0/src/movoice/resources/messages.py +41 -0
- movoice-0.1.0/src/movoice/resources/numbers.py +30 -0
- movoice-0.1.0/src/movoice/types.py +345 -0
- movoice-0.1.0/src/movoice/webhooks.py +134 -0
- movoice-0.1.0/tests/test_client.py +620 -0
- movoice-0.1.0/tests/test_webhooks.py +194 -0
movoice-0.1.0/.gitignore
ADDED
movoice-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Movoice AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
movoice-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: movoice
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The official Python client for the Movoice AI API: voice agents, calls, contacts, bookings, SMS, WhatsApp and webhook verification
|
|
5
|
+
Project-URL: Homepage, https://docs.movoice.ai
|
|
6
|
+
Project-URL: Documentation, https://docs.movoice.ai
|
|
7
|
+
Project-URL: API reference, https://app.movoice.ai/api/v1/openapi.json
|
|
8
|
+
Author-email: Movoice AI <care@movoice.ai>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api-client,crm,movoice,sdk,sms,telephony,voice-agents,voice-ai,webhooks,whatsapp
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Communications :: Telephony
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Requires-Dist: httpx<1,>=0.25
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# movoice
|
|
34
|
+
|
|
35
|
+
The official Python client for the [Movoice AI](https://movoice.ai) API: voice agents, calls,
|
|
36
|
+
contacts, bookings, SMS, WhatsApp, and webhook verification.
|
|
37
|
+
|
|
38
|
+
Python 3.9+. One dependency ([httpx](https://www.python-httpx.org)). Fully typed.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install movoice
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
> **Rolling out:** the call-result fields `id`, `context_data` and `agent`, and giving an agent a phone number with `agents.update(agent_id, phone_number=...)`, arrive with the December 2026 Movoice release. Until then they are already on Movoice's testing server.
|
|
45
|
+
|
|
46
|
+
## Call a lead from your CRM and get the result back
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import os
|
|
50
|
+
from movoice import Movoice
|
|
51
|
+
|
|
52
|
+
client = Movoice() # reads MOVOICE_API_KEY
|
|
53
|
+
|
|
54
|
+
# 1. Your CRM says "call this lead". context_data fills {name} in the agent's prompt and comes back on every event.
|
|
55
|
+
call = client.calls.create(
|
|
56
|
+
agent_id=os.environ["MOVOICE_AGENT_ID"],
|
|
57
|
+
phone_number="+14155550123",
|
|
58
|
+
context_data={"leadId": "L-889", "name": "Rahul"},
|
|
59
|
+
idempotency_key="call-L-889-1", # retry safely: the same key never dials twice
|
|
60
|
+
)
|
|
61
|
+
crm.save_call_id("L-889", call["id"])
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
# 2. Movoice posts call.completed to your webhook. Verify it, then match it back to the lead. (FastAPI)
|
|
66
|
+
import os
|
|
67
|
+
import movoice
|
|
68
|
+
from fastapi import FastAPI, Request, Response
|
|
69
|
+
|
|
70
|
+
app = FastAPI()
|
|
71
|
+
|
|
72
|
+
@app.post("/movoice-webhook")
|
|
73
|
+
async def movoice_webhook(request: Request):
|
|
74
|
+
try:
|
|
75
|
+
event = movoice.webhooks.verify(await request.body(), request.headers, os.environ["MOVOICE_WEBHOOK_SECRET"])
|
|
76
|
+
except movoice.WebhookVerificationError:
|
|
77
|
+
return Response(status_code=400)
|
|
78
|
+
if event["event"] == "call.completed":
|
|
79
|
+
crm.log_call(event.get("context_data", {}).get("leadId"), event.get("summary"), event.get("duration_seconds"))
|
|
80
|
+
return Response(status_code=200)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The same receiver in Flask:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from flask import Flask, request
|
|
87
|
+
|
|
88
|
+
app = Flask(__name__)
|
|
89
|
+
|
|
90
|
+
@app.post("/movoice-webhook")
|
|
91
|
+
def movoice_webhook():
|
|
92
|
+
try:
|
|
93
|
+
event = movoice.webhooks.verify(request.get_data(), request.headers, os.environ["MOVOICE_WEBHOOK_SECRET"])
|
|
94
|
+
except movoice.WebhookVerificationError:
|
|
95
|
+
return "", 400
|
|
96
|
+
...
|
|
97
|
+
return "", 200
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`call["id"]` is the call's Movoice id. Every webhook for that call carries it as `id`, plus the
|
|
101
|
+
`context_data` you sent and the agent as `agent["id"]`, so either one leads back to the record in
|
|
102
|
+
your CRM. `client.calls.get(call["id"])` reads the call (status, duration, `summary`, transcript)
|
|
103
|
+
whenever you want it instead.
|
|
104
|
+
|
|
105
|
+
Responses are plain `dict`s with the API's own keys (`call["movoiceWebSocketCallId"]`,
|
|
106
|
+
`agent["welcomeMessage"]`); `movoice.types` has `TypedDict`s describing each one for your editor.
|
|
107
|
+
Arguments are Python keyword arguments (`agent_id=`, `phone_number=`, `context_data=`).
|
|
108
|
+
|
|
109
|
+
## Test keys and live keys
|
|
110
|
+
|
|
111
|
+
Create keys on the Developer page: https://app.movoice.ai/admin/developer
|
|
112
|
+
|
|
113
|
+
| Key | What it does |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| `mv_live_...` | The real thing. Calls dial and are charged; writes change your account. |
|
|
116
|
+
| `mv_test_...` | A sandbox. `calls.create` places a pretend call (`id` starts with `test_call_`, `livemode: False`) that dials nobody and costs nothing, and your webhook endpoints receive pretend `call.started` and `call.completed` events for it, carrying your `context_data`. Reads return sample data; writes answer with `livemode: False` and change nothing. |
|
|
117
|
+
| `mv_pk_...` | Publishable, for the chat widget in a browser. It cannot call this API, and the client refuses it at construction. |
|
|
118
|
+
|
|
119
|
+
Build and test the whole loop with a test key, then swap in the live key.
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
client = Movoice() # MOVOICE_API_KEY from the environment
|
|
123
|
+
client = Movoice("mv_test_...") # or pass it
|
|
124
|
+
client = Movoice(base_url="https://testing.movoice.ai", timeout=10, max_retries=0)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Keep your key on your server: a secret key can place calls and spend your balance.
|
|
128
|
+
|
|
129
|
+
## Errors
|
|
130
|
+
|
|
131
|
+
Every failure raises. One class hierarchy, whatever shape the API replied with:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
import movoice
|
|
135
|
+
|
|
136
|
+
try:
|
|
137
|
+
client.calls.create(agent_id=agent_id, phone_number=phone)
|
|
138
|
+
except movoice.InsufficientBalanceError:
|
|
139
|
+
top_up_wallet()
|
|
140
|
+
except movoice.RateLimitError as err:
|
|
141
|
+
retry_later(err.retry_after)
|
|
142
|
+
except movoice.MovoiceError as err:
|
|
143
|
+
print(err.code, err.message, err.status)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
| Class | When |
|
|
147
|
+
| --- | --- |
|
|
148
|
+
| `AuthenticationError` | 401: key missing, expired, or unknown |
|
|
149
|
+
| `PermissionError` | 403: key lacks the scope. `err.required_scopes` lists what it needed |
|
|
150
|
+
| `InvalidRequestError` | 400 / 422. `err.field_errors` has per-field messages |
|
|
151
|
+
| `NotFoundError` | 404: also returned for another account's ids |
|
|
152
|
+
| `ConflictError` | 409: conflicts with the current state |
|
|
153
|
+
| `InsufficientBalanceError` | 402: plan allowance and wallet both empty |
|
|
154
|
+
| `RateLimitError` | 429. `err.retry_after` in seconds, when the API sent one |
|
|
155
|
+
| `ApiError` | 5xx |
|
|
156
|
+
| `ConnectionError` | never reached the server, or timed out (`err.code == "TIMEOUT"`) |
|
|
157
|
+
|
|
158
|
+
`movoice.PermissionError` and `movoice.ConnectionError` share their names with Python built-ins,
|
|
159
|
+
like the other Movoice clients; use them through the package (`movoice.PermissionError`), or catch
|
|
160
|
+
`movoice.MovoiceError` for everything. `err.code` is normalised to upper case; the API's own value
|
|
161
|
+
is on `err.raw_code`, and the parsed body on `err.body`.
|
|
162
|
+
|
|
163
|
+
## Retries and idempotency
|
|
164
|
+
|
|
165
|
+
Retried automatically: `429` on any method, and `5xx` or network faults **on GET**.
|
|
166
|
+
|
|
167
|
+
A `POST` or `PATCH` that failed with a `5xx` or timed out is **not** retried on its own: a `500`
|
|
168
|
+
does not tell you whether the work happened first, and retrying `calls.create` would place a
|
|
169
|
+
second call and bill you twice.
|
|
170
|
+
|
|
171
|
+
Unless you give it an idempotency key. `calls.create`, `agents.create`, `agents.update`,
|
|
172
|
+
`appointments.create`, `appointments.cancel` and `appointments.reschedule` take
|
|
173
|
+
`idempotency_key=`, sent as the `Idempotency-Key` header. The server keeps the first answer under
|
|
174
|
+
that key and hands it back for any repeat instead of acting again, so with a key the client does
|
|
175
|
+
retry a timeout or a `5xx`, and so can you. Use one key per thing you mean to happen once; reusing
|
|
176
|
+
a key with a different body is refused (`422`), and a repeat that arrives while the first is still
|
|
177
|
+
running gets `ConflictError` (`409`). Keys are 8 to 255 characters. Methods that do not accept a
|
|
178
|
+
key do not take the argument at all.
|
|
179
|
+
|
|
180
|
+
Tune with `Movoice(max_retries=0)`, or `timeout=` (seconds, default 30) per client or per call.
|
|
181
|
+
|
|
182
|
+
## Webhooks
|
|
183
|
+
|
|
184
|
+
Add an endpoint on the Developer page and copy its signing secret (it starts with `whsec_`).
|
|
185
|
+
Every delivery is signed:
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
X-Movoice-Timestamp: <unix seconds>
|
|
189
|
+
X-Movoice-Signature: sha256=<hex HMAC-SHA256 of "<timestamp>.<raw body>", keyed with the whole whsec_ secret>
|
|
190
|
+
X-Movoice-Event: call.completed
|
|
191
|
+
X-Movoice-Delivery: <event_id>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`movoice.webhooks.verify(raw_body, headers, secret, tolerance=300)` checks the signature
|
|
195
|
+
(constant-time, `hmac.compare_digest`) and that the timestamp is within 5 minutes of now, then
|
|
196
|
+
returns the parsed event. Anything else raises `WebhookVerificationError`
|
|
197
|
+
(`code == "WEBHOOK_SIGNATURE_INVALID"`): answer it with a 400.
|
|
198
|
+
|
|
199
|
+
Pass the body **exactly as it arrived** (`str` or `bytes`: Flask `request.get_data()`,
|
|
200
|
+
FastAPI/Starlette `await request.body()`, Django `request.body`), never parsed JSON. `headers` may
|
|
201
|
+
be a dict or any headers object; names are matched case-insensitively. It needs no API key;
|
|
202
|
+
`client.webhooks.verify` is the same function. Events: `call.started`, `call.completed`,
|
|
203
|
+
`call.failed`, `call.missed`. Answer quickly with a 2xx: a failed delivery is retried with the same
|
|
204
|
+
`event_id`, so drop duplicates by it.
|
|
205
|
+
|
|
206
|
+
## Paging
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
page = client.calls.list(per_page=50, agent_id=agent_id)
|
|
210
|
+
page.data # list of calls
|
|
211
|
+
page.has_more
|
|
212
|
+
page.total # may be None: the set can be too large to count
|
|
213
|
+
nxt = page.next() # Page or None
|
|
214
|
+
|
|
215
|
+
for call in client.calls.list_all(agent_id=agent_id): # every page, fetched as you go
|
|
216
|
+
print(call["id"], call["status"])
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`next()` follows a cursor where the endpoint offers one (`/calls`) and increments the page number
|
|
220
|
+
where it does not, so the same loop is correct everywhere.
|
|
221
|
+
|
|
222
|
+
## Hang up a call
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
client.calls.hangup(call["id"]) # the network is asked to end it; call.completed follows
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Give an agent a phone number
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
client.agents.update(agent_id, phone_number="+14155550123") # or the number's id from numbers.list()
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
The agent then answers that number, as when you pick it in the dashboard. A number not on your
|
|
235
|
+
account raises `NotFoundError`; one another agent answers raises `ConflictError`.
|
|
236
|
+
|
|
237
|
+
## Contacts
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
existing = client.contacts.list(search="+14155550123")
|
|
241
|
+
contact = existing[0] if existing else client.contacts.create(name="Rahul", phone="+14155550123", tags=["crm"])
|
|
242
|
+
client.contacts.update(contact["id"], notes="Wants a callback on Thursday")
|
|
243
|
+
client.contacts.delete(contact["id"])
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
`list` returns up to `per_page` (max 100) contacts, newest first, with no paging: narrow it with
|
|
247
|
+
`search`. A second contact with the same phone raises `ConflictError`.
|
|
248
|
+
|
|
249
|
+
## Appointments and availability
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
slots = client.availability.get(agent_id=agent_id, date="2026-12-01", timezone="Asia/Kolkata")["slots"]
|
|
253
|
+
booking = client.appointments.create(
|
|
254
|
+
agent_id=agent_id, customer_name="Rahul", customer_phone="+919845000001",
|
|
255
|
+
date="2026-12-01", time=slots[0], idempotency_key="book-L-889",
|
|
256
|
+
)
|
|
257
|
+
client.appointments.reschedule(booking["id"], date="2026-12-02", time="11:00")
|
|
258
|
+
client.appointments.cancel(booking["id"], tell_customer=True)
|
|
259
|
+
|
|
260
|
+
for a in client.appointments.list_all(from_="2026-12-01", to="2026-12-31"):
|
|
261
|
+
print(a["date"], a["time"])
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`from_` has a trailing underscore because `from` is a Python keyword.
|
|
265
|
+
|
|
266
|
+
## Sending messages
|
|
267
|
+
|
|
268
|
+
```python
|
|
269
|
+
client.messages.send(to="+14155550123", body="Your appointment is confirmed.")
|
|
270
|
+
client.messages.send_whatsapp(to="+14155550123", body="Your appointment is confirmed.")
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Both spend your balance and are capped at 500 messages per key per 24 hours. The response field
|
|
274
|
+
`status` is always `"sent"`; the honest signal is `providerMessageId`, and the client raises
|
|
275
|
+
(`code == "NOT_SENT"`) when a nominally successful response carries none. A recipient who replied
|
|
276
|
+
STOP is suppressed on every channel and raises `InvalidRequestError`.
|
|
277
|
+
|
|
278
|
+
## Caller memory and your account
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
memory = client.memory.recall(agent_id=agent_id, phone="+14155550123")
|
|
282
|
+
if memory["found"]:
|
|
283
|
+
print(memory["data"]["total_calls"], memory["data"]["facts"])
|
|
284
|
+
else:
|
|
285
|
+
print(memory["message"]) # no memory yet, memory switched off, or unknown caller
|
|
286
|
+
|
|
287
|
+
account = client.account.get()
|
|
288
|
+
account["accountNumber"] # your Movoice Account ID: quote it to support
|
|
289
|
+
account["creditBalanceUsdCents"] # US cents, whatever currency you pay in
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Conventions
|
|
293
|
+
|
|
294
|
+
- Every timestamp is **epoch milliseconds**; a call's `duration` is **seconds**.
|
|
295
|
+
- An agent's `bolnaAgentId` key is its engine id inside the Movoice WebSocket voice engine (the key
|
|
296
|
+
name the API has always sent); use `id` everywhere else.
|
|
297
|
+
- `client.http.request("GET", "/some/new/endpoint")` reaches anything this version does not wrap
|
|
298
|
+
yet, with the same auth, retries and errors. Paths are relative to `/api/v1`.
|
|
299
|
+
|
|
300
|
+
## Reference
|
|
301
|
+
|
|
302
|
+
Docs: https://docs.movoice.ai. The machine-readable spec lives at
|
|
303
|
+
[`/api/v1/openapi.json`](https://app.movoice.ai/api/v1/openapi.json).
|
|
304
|
+
|
|
305
|
+
## Licence
|
|
306
|
+
|
|
307
|
+
MIT
|
movoice-0.1.0/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# movoice
|
|
2
|
+
|
|
3
|
+
The official Python client for the [Movoice AI](https://movoice.ai) API: voice agents, calls,
|
|
4
|
+
contacts, bookings, SMS, WhatsApp, and webhook verification.
|
|
5
|
+
|
|
6
|
+
Python 3.9+. One dependency ([httpx](https://www.python-httpx.org)). Fully typed.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install movoice
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
> **Rolling out:** the call-result fields `id`, `context_data` and `agent`, and giving an agent a phone number with `agents.update(agent_id, phone_number=...)`, arrive with the December 2026 Movoice release. Until then they are already on Movoice's testing server.
|
|
13
|
+
|
|
14
|
+
## Call a lead from your CRM and get the result back
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import os
|
|
18
|
+
from movoice import Movoice
|
|
19
|
+
|
|
20
|
+
client = Movoice() # reads MOVOICE_API_KEY
|
|
21
|
+
|
|
22
|
+
# 1. Your CRM says "call this lead". context_data fills {name} in the agent's prompt and comes back on every event.
|
|
23
|
+
call = client.calls.create(
|
|
24
|
+
agent_id=os.environ["MOVOICE_AGENT_ID"],
|
|
25
|
+
phone_number="+14155550123",
|
|
26
|
+
context_data={"leadId": "L-889", "name": "Rahul"},
|
|
27
|
+
idempotency_key="call-L-889-1", # retry safely: the same key never dials twice
|
|
28
|
+
)
|
|
29
|
+
crm.save_call_id("L-889", call["id"])
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
# 2. Movoice posts call.completed to your webhook. Verify it, then match it back to the lead. (FastAPI)
|
|
34
|
+
import os
|
|
35
|
+
import movoice
|
|
36
|
+
from fastapi import FastAPI, Request, Response
|
|
37
|
+
|
|
38
|
+
app = FastAPI()
|
|
39
|
+
|
|
40
|
+
@app.post("/movoice-webhook")
|
|
41
|
+
async def movoice_webhook(request: Request):
|
|
42
|
+
try:
|
|
43
|
+
event = movoice.webhooks.verify(await request.body(), request.headers, os.environ["MOVOICE_WEBHOOK_SECRET"])
|
|
44
|
+
except movoice.WebhookVerificationError:
|
|
45
|
+
return Response(status_code=400)
|
|
46
|
+
if event["event"] == "call.completed":
|
|
47
|
+
crm.log_call(event.get("context_data", {}).get("leadId"), event.get("summary"), event.get("duration_seconds"))
|
|
48
|
+
return Response(status_code=200)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The same receiver in Flask:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from flask import Flask, request
|
|
55
|
+
|
|
56
|
+
app = Flask(__name__)
|
|
57
|
+
|
|
58
|
+
@app.post("/movoice-webhook")
|
|
59
|
+
def movoice_webhook():
|
|
60
|
+
try:
|
|
61
|
+
event = movoice.webhooks.verify(request.get_data(), request.headers, os.environ["MOVOICE_WEBHOOK_SECRET"])
|
|
62
|
+
except movoice.WebhookVerificationError:
|
|
63
|
+
return "", 400
|
|
64
|
+
...
|
|
65
|
+
return "", 200
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`call["id"]` is the call's Movoice id. Every webhook for that call carries it as `id`, plus the
|
|
69
|
+
`context_data` you sent and the agent as `agent["id"]`, so either one leads back to the record in
|
|
70
|
+
your CRM. `client.calls.get(call["id"])` reads the call (status, duration, `summary`, transcript)
|
|
71
|
+
whenever you want it instead.
|
|
72
|
+
|
|
73
|
+
Responses are plain `dict`s with the API's own keys (`call["movoiceWebSocketCallId"]`,
|
|
74
|
+
`agent["welcomeMessage"]`); `movoice.types` has `TypedDict`s describing each one for your editor.
|
|
75
|
+
Arguments are Python keyword arguments (`agent_id=`, `phone_number=`, `context_data=`).
|
|
76
|
+
|
|
77
|
+
## Test keys and live keys
|
|
78
|
+
|
|
79
|
+
Create keys on the Developer page: https://app.movoice.ai/admin/developer
|
|
80
|
+
|
|
81
|
+
| Key | What it does |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| `mv_live_...` | The real thing. Calls dial and are charged; writes change your account. |
|
|
84
|
+
| `mv_test_...` | A sandbox. `calls.create` places a pretend call (`id` starts with `test_call_`, `livemode: False`) that dials nobody and costs nothing, and your webhook endpoints receive pretend `call.started` and `call.completed` events for it, carrying your `context_data`. Reads return sample data; writes answer with `livemode: False` and change nothing. |
|
|
85
|
+
| `mv_pk_...` | Publishable, for the chat widget in a browser. It cannot call this API, and the client refuses it at construction. |
|
|
86
|
+
|
|
87
|
+
Build and test the whole loop with a test key, then swap in the live key.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
client = Movoice() # MOVOICE_API_KEY from the environment
|
|
91
|
+
client = Movoice("mv_test_...") # or pass it
|
|
92
|
+
client = Movoice(base_url="https://testing.movoice.ai", timeout=10, max_retries=0)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Keep your key on your server: a secret key can place calls and spend your balance.
|
|
96
|
+
|
|
97
|
+
## Errors
|
|
98
|
+
|
|
99
|
+
Every failure raises. One class hierarchy, whatever shape the API replied with:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
import movoice
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
client.calls.create(agent_id=agent_id, phone_number=phone)
|
|
106
|
+
except movoice.InsufficientBalanceError:
|
|
107
|
+
top_up_wallet()
|
|
108
|
+
except movoice.RateLimitError as err:
|
|
109
|
+
retry_later(err.retry_after)
|
|
110
|
+
except movoice.MovoiceError as err:
|
|
111
|
+
print(err.code, err.message, err.status)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
| Class | When |
|
|
115
|
+
| --- | --- |
|
|
116
|
+
| `AuthenticationError` | 401: key missing, expired, or unknown |
|
|
117
|
+
| `PermissionError` | 403: key lacks the scope. `err.required_scopes` lists what it needed |
|
|
118
|
+
| `InvalidRequestError` | 400 / 422. `err.field_errors` has per-field messages |
|
|
119
|
+
| `NotFoundError` | 404: also returned for another account's ids |
|
|
120
|
+
| `ConflictError` | 409: conflicts with the current state |
|
|
121
|
+
| `InsufficientBalanceError` | 402: plan allowance and wallet both empty |
|
|
122
|
+
| `RateLimitError` | 429. `err.retry_after` in seconds, when the API sent one |
|
|
123
|
+
| `ApiError` | 5xx |
|
|
124
|
+
| `ConnectionError` | never reached the server, or timed out (`err.code == "TIMEOUT"`) |
|
|
125
|
+
|
|
126
|
+
`movoice.PermissionError` and `movoice.ConnectionError` share their names with Python built-ins,
|
|
127
|
+
like the other Movoice clients; use them through the package (`movoice.PermissionError`), or catch
|
|
128
|
+
`movoice.MovoiceError` for everything. `err.code` is normalised to upper case; the API's own value
|
|
129
|
+
is on `err.raw_code`, and the parsed body on `err.body`.
|
|
130
|
+
|
|
131
|
+
## Retries and idempotency
|
|
132
|
+
|
|
133
|
+
Retried automatically: `429` on any method, and `5xx` or network faults **on GET**.
|
|
134
|
+
|
|
135
|
+
A `POST` or `PATCH` that failed with a `5xx` or timed out is **not** retried on its own: a `500`
|
|
136
|
+
does not tell you whether the work happened first, and retrying `calls.create` would place a
|
|
137
|
+
second call and bill you twice.
|
|
138
|
+
|
|
139
|
+
Unless you give it an idempotency key. `calls.create`, `agents.create`, `agents.update`,
|
|
140
|
+
`appointments.create`, `appointments.cancel` and `appointments.reschedule` take
|
|
141
|
+
`idempotency_key=`, sent as the `Idempotency-Key` header. The server keeps the first answer under
|
|
142
|
+
that key and hands it back for any repeat instead of acting again, so with a key the client does
|
|
143
|
+
retry a timeout or a `5xx`, and so can you. Use one key per thing you mean to happen once; reusing
|
|
144
|
+
a key with a different body is refused (`422`), and a repeat that arrives while the first is still
|
|
145
|
+
running gets `ConflictError` (`409`). Keys are 8 to 255 characters. Methods that do not accept a
|
|
146
|
+
key do not take the argument at all.
|
|
147
|
+
|
|
148
|
+
Tune with `Movoice(max_retries=0)`, or `timeout=` (seconds, default 30) per client or per call.
|
|
149
|
+
|
|
150
|
+
## Webhooks
|
|
151
|
+
|
|
152
|
+
Add an endpoint on the Developer page and copy its signing secret (it starts with `whsec_`).
|
|
153
|
+
Every delivery is signed:
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
X-Movoice-Timestamp: <unix seconds>
|
|
157
|
+
X-Movoice-Signature: sha256=<hex HMAC-SHA256 of "<timestamp>.<raw body>", keyed with the whole whsec_ secret>
|
|
158
|
+
X-Movoice-Event: call.completed
|
|
159
|
+
X-Movoice-Delivery: <event_id>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`movoice.webhooks.verify(raw_body, headers, secret, tolerance=300)` checks the signature
|
|
163
|
+
(constant-time, `hmac.compare_digest`) and that the timestamp is within 5 minutes of now, then
|
|
164
|
+
returns the parsed event. Anything else raises `WebhookVerificationError`
|
|
165
|
+
(`code == "WEBHOOK_SIGNATURE_INVALID"`): answer it with a 400.
|
|
166
|
+
|
|
167
|
+
Pass the body **exactly as it arrived** (`str` or `bytes`: Flask `request.get_data()`,
|
|
168
|
+
FastAPI/Starlette `await request.body()`, Django `request.body`), never parsed JSON. `headers` may
|
|
169
|
+
be a dict or any headers object; names are matched case-insensitively. It needs no API key;
|
|
170
|
+
`client.webhooks.verify` is the same function. Events: `call.started`, `call.completed`,
|
|
171
|
+
`call.failed`, `call.missed`. Answer quickly with a 2xx: a failed delivery is retried with the same
|
|
172
|
+
`event_id`, so drop duplicates by it.
|
|
173
|
+
|
|
174
|
+
## Paging
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
page = client.calls.list(per_page=50, agent_id=agent_id)
|
|
178
|
+
page.data # list of calls
|
|
179
|
+
page.has_more
|
|
180
|
+
page.total # may be None: the set can be too large to count
|
|
181
|
+
nxt = page.next() # Page or None
|
|
182
|
+
|
|
183
|
+
for call in client.calls.list_all(agent_id=agent_id): # every page, fetched as you go
|
|
184
|
+
print(call["id"], call["status"])
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
`next()` follows a cursor where the endpoint offers one (`/calls`) and increments the page number
|
|
188
|
+
where it does not, so the same loop is correct everywhere.
|
|
189
|
+
|
|
190
|
+
## Hang up a call
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
client.calls.hangup(call["id"]) # the network is asked to end it; call.completed follows
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Give an agent a phone number
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
client.agents.update(agent_id, phone_number="+14155550123") # or the number's id from numbers.list()
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
The agent then answers that number, as when you pick it in the dashboard. A number not on your
|
|
203
|
+
account raises `NotFoundError`; one another agent answers raises `ConflictError`.
|
|
204
|
+
|
|
205
|
+
## Contacts
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
existing = client.contacts.list(search="+14155550123")
|
|
209
|
+
contact = existing[0] if existing else client.contacts.create(name="Rahul", phone="+14155550123", tags=["crm"])
|
|
210
|
+
client.contacts.update(contact["id"], notes="Wants a callback on Thursday")
|
|
211
|
+
client.contacts.delete(contact["id"])
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`list` returns up to `per_page` (max 100) contacts, newest first, with no paging: narrow it with
|
|
215
|
+
`search`. A second contact with the same phone raises `ConflictError`.
|
|
216
|
+
|
|
217
|
+
## Appointments and availability
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
slots = client.availability.get(agent_id=agent_id, date="2026-12-01", timezone="Asia/Kolkata")["slots"]
|
|
221
|
+
booking = client.appointments.create(
|
|
222
|
+
agent_id=agent_id, customer_name="Rahul", customer_phone="+919845000001",
|
|
223
|
+
date="2026-12-01", time=slots[0], idempotency_key="book-L-889",
|
|
224
|
+
)
|
|
225
|
+
client.appointments.reschedule(booking["id"], date="2026-12-02", time="11:00")
|
|
226
|
+
client.appointments.cancel(booking["id"], tell_customer=True)
|
|
227
|
+
|
|
228
|
+
for a in client.appointments.list_all(from_="2026-12-01", to="2026-12-31"):
|
|
229
|
+
print(a["date"], a["time"])
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`from_` has a trailing underscore because `from` is a Python keyword.
|
|
233
|
+
|
|
234
|
+
## Sending messages
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
client.messages.send(to="+14155550123", body="Your appointment is confirmed.")
|
|
238
|
+
client.messages.send_whatsapp(to="+14155550123", body="Your appointment is confirmed.")
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Both spend your balance and are capped at 500 messages per key per 24 hours. The response field
|
|
242
|
+
`status` is always `"sent"`; the honest signal is `providerMessageId`, and the client raises
|
|
243
|
+
(`code == "NOT_SENT"`) when a nominally successful response carries none. A recipient who replied
|
|
244
|
+
STOP is suppressed on every channel and raises `InvalidRequestError`.
|
|
245
|
+
|
|
246
|
+
## Caller memory and your account
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
memory = client.memory.recall(agent_id=agent_id, phone="+14155550123")
|
|
250
|
+
if memory["found"]:
|
|
251
|
+
print(memory["data"]["total_calls"], memory["data"]["facts"])
|
|
252
|
+
else:
|
|
253
|
+
print(memory["message"]) # no memory yet, memory switched off, or unknown caller
|
|
254
|
+
|
|
255
|
+
account = client.account.get()
|
|
256
|
+
account["accountNumber"] # your Movoice Account ID: quote it to support
|
|
257
|
+
account["creditBalanceUsdCents"] # US cents, whatever currency you pay in
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Conventions
|
|
261
|
+
|
|
262
|
+
- Every timestamp is **epoch milliseconds**; a call's `duration` is **seconds**.
|
|
263
|
+
- An agent's `bolnaAgentId` key is its engine id inside the Movoice WebSocket voice engine (the key
|
|
264
|
+
name the API has always sent); use `id` everywhere else.
|
|
265
|
+
- `client.http.request("GET", "/some/new/endpoint")` reaches anything this version does not wrap
|
|
266
|
+
yet, with the same auth, retries and errors. Paths are relative to `/api/v1`.
|
|
267
|
+
|
|
268
|
+
## Reference
|
|
269
|
+
|
|
270
|
+
Docs: https://docs.movoice.ai. The machine-readable spec lives at
|
|
271
|
+
[`/api/v1/openapi.json`](https://app.movoice.ai/api/v1/openapi.json).
|
|
272
|
+
|
|
273
|
+
## Licence
|
|
274
|
+
|
|
275
|
+
MIT
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "movoice"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "The official Python client for the Movoice AI API: voice agents, calls, contacts, bookings, SMS, WhatsApp and webhook verification"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Movoice AI", email = "care@movoice.ai" }]
|
|
14
|
+
keywords = [
|
|
15
|
+
"movoice",
|
|
16
|
+
"voice-ai",
|
|
17
|
+
"voice-agents",
|
|
18
|
+
"telephony",
|
|
19
|
+
"sms",
|
|
20
|
+
"whatsapp",
|
|
21
|
+
"api-client",
|
|
22
|
+
"sdk",
|
|
23
|
+
"webhooks",
|
|
24
|
+
"crm",
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 4 - Beta",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"Operating System :: OS Independent",
|
|
30
|
+
"Programming Language :: Python",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
33
|
+
"Programming Language :: Python :: 3.9",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
"Programming Language :: Python :: 3.13",
|
|
38
|
+
"Programming Language :: Python :: 3.14",
|
|
39
|
+
"Topic :: Communications :: Telephony",
|
|
40
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
41
|
+
"Typing :: Typed",
|
|
42
|
+
]
|
|
43
|
+
dependencies = ["httpx>=0.25,<1"]
|
|
44
|
+
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
dev = ["pytest>=7"]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://docs.movoice.ai"
|
|
50
|
+
Documentation = "https://docs.movoice.ai"
|
|
51
|
+
"API reference" = "https://app.movoice.ai/api/v1/openapi.json"
|
|
52
|
+
|
|
53
|
+
[tool.hatch.version]
|
|
54
|
+
path = "src/movoice/_version.py"
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build.targets.wheel]
|
|
57
|
+
packages = ["src/movoice"]
|
|
58
|
+
|
|
59
|
+
[tool.hatch.build.targets.sdist]
|
|
60
|
+
include = ["src/movoice", "tests", "README.md", "LICENSE", "pyproject.toml"]
|
|
61
|
+
|
|
62
|
+
[tool.pytest.ini_options]
|
|
63
|
+
testpaths = ["tests"]
|