@noematicsllc/talk-sdk 0.0.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 +171 -0
- package/dist/index.d.mts +2147 -0
- package/dist/index.d.ts +2147 -0
- package/dist/index.js +1864 -0
- package/dist/index.mjs +1805 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# @noematicsllc/talk-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the Nextcloud Talk API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @noematicsllc/talk-sdk
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @noematicsllc/talk-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { TalkClient } from '@noematicsllc/talk-sdk';
|
|
17
|
+
|
|
18
|
+
const client = new TalkClient({
|
|
19
|
+
host: 'https://nextcloud.local',
|
|
20
|
+
username: 'admin',
|
|
21
|
+
password: 'app-password'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// List all rooms
|
|
25
|
+
const rooms = await client.rooms.list();
|
|
26
|
+
|
|
27
|
+
// Find a room by token
|
|
28
|
+
const targetRoom = rooms.find(r => r.token === 'abcdefgh');
|
|
29
|
+
|
|
30
|
+
// Send a message
|
|
31
|
+
await targetRoom.sendMessage("Automated system check initialized.");
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Architecture
|
|
35
|
+
|
|
36
|
+
The SDK uses a 4-layer architecture:
|
|
37
|
+
|
|
38
|
+
### 1. Transport Layer (`HttpClient`)
|
|
39
|
+
|
|
40
|
+
Base HTTP client using the native Fetch API. Automatically injects mandatory OCS headers:
|
|
41
|
+
- `OCS-APIRequest: true`
|
|
42
|
+
- `Accept: application/json`
|
|
43
|
+
- `Authorization: Basic ...`
|
|
44
|
+
|
|
45
|
+
### 2. Resource Layer
|
|
46
|
+
|
|
47
|
+
Logical modules mapped to specific API versions:
|
|
48
|
+
|
|
49
|
+
| Resource | API Version | Base Path |
|
|
50
|
+
|----------|-------------|-----------|
|
|
51
|
+
| `RoomResource` | v4 | `/api/v4/room` |
|
|
52
|
+
| `ParticipantResource` | v4 | `/api/v4/room/{token}/participants` |
|
|
53
|
+
| `CallResource` | v4 | `/api/v4/call` |
|
|
54
|
+
| `ChatResource` | v1 | `/api/v1/chat` |
|
|
55
|
+
| `PollResource` | v1 | `/api/v1/poll` |
|
|
56
|
+
| `ReactionResource` | v1 | `/api/v1/reaction` |
|
|
57
|
+
|
|
58
|
+
### 3. Normalization Layer
|
|
59
|
+
|
|
60
|
+
DTO mappers that strip the `ocs.meta` and `ocs.data` envelopes, returning clean, flat objects.
|
|
61
|
+
|
|
62
|
+
### 4. Domain Layer
|
|
63
|
+
|
|
64
|
+
High-level entities like `Room` that encapsulate both the `token` (string) and `id` (integer) to handle the API's identifier inconsistencies.
|
|
65
|
+
|
|
66
|
+
## Room Entity
|
|
67
|
+
|
|
68
|
+
The `Room` class provides a high-level interface for room operations:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
const room = await client.rooms.get('abcdefgh');
|
|
72
|
+
|
|
73
|
+
// Chat
|
|
74
|
+
await room.sendMessage("Hello!");
|
|
75
|
+
const messages = await room.getHistory({ limit: 50 });
|
|
76
|
+
const result = await room.pollMessages({ lastKnownMessageId: 123 });
|
|
77
|
+
|
|
78
|
+
// Participants
|
|
79
|
+
const participants = await room.getParticipants();
|
|
80
|
+
await room.addParticipant('user-id');
|
|
81
|
+
|
|
82
|
+
// Calls
|
|
83
|
+
await room.joinCall({ flags: 7 });
|
|
84
|
+
const peers = await room.getCallPeers();
|
|
85
|
+
await room.leaveCall();
|
|
86
|
+
|
|
87
|
+
// Polls
|
|
88
|
+
await room.createPoll({
|
|
89
|
+
question: "What's for lunch?",
|
|
90
|
+
options: ["Pizza", "Sushi", "Tacos"]
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Reactions
|
|
94
|
+
await room.addReaction(messageId, "👍");
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Message Polling
|
|
98
|
+
|
|
99
|
+
Implement efficient message polling using the spec's pattern:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
let lastKnownMessageId = 0;
|
|
103
|
+
|
|
104
|
+
while (polling) {
|
|
105
|
+
const result = await room.pollMessages({
|
|
106
|
+
lastKnownMessageId,
|
|
107
|
+
timeout: 30, // Long-poll timeout
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
for (const message of result.messages) {
|
|
111
|
+
console.log(`${message.actorDisplayName}: ${message.message}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (result.lastKnownMessageId) {
|
|
115
|
+
lastKnownMessageId = result.lastKnownMessageId;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Direct Resource Access
|
|
121
|
+
|
|
122
|
+
For advanced use cases, access resources directly:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
// Direct resource access
|
|
126
|
+
const roomData = await client.roomResource.get('token');
|
|
127
|
+
const messages = await client.chat.receiveMessages('token', {
|
|
128
|
+
lookIntoFuture: 0,
|
|
129
|
+
limit: 100,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Raw HTTP access
|
|
133
|
+
const response = await client.http.get('/custom/endpoint');
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Types
|
|
137
|
+
|
|
138
|
+
All API types are exported for TypeScript users:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import {
|
|
142
|
+
TalkRoom,
|
|
143
|
+
TalkChatMessage,
|
|
144
|
+
TalkParticipant,
|
|
145
|
+
ConversationType,
|
|
146
|
+
ParticipantType,
|
|
147
|
+
Permission,
|
|
148
|
+
InCallFlag,
|
|
149
|
+
} from '@noematicsllc/talk-sdk';
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Error Handling
|
|
153
|
+
|
|
154
|
+
The SDK throws `HttpClientError` for API errors:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { HttpClientError } from '@noematicsllc/talk-sdk';
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
await client.rooms.get('invalid-token');
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (error instanceof HttpClientError) {
|
|
163
|
+
console.error(`HTTP ${error.status}: ${error.message}`);
|
|
164
|
+
console.error(`OCS Status: ${error.ocsStatus}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
MIT
|