@talkey/sdk 1.0.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 +160 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +68 -0
- package/package.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# 🚀 Talkey SDK (JavaScript / TypeScript)
|
|
2
|
+
|
|
3
|
+
Send SMS and WhatsApp messages easily with Talkey.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📦 Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install talkey
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ⚡ Quick Start
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { Talkey } from "talkey"
|
|
19
|
+
|
|
20
|
+
const talkey = new Talkey("YOUR_API_KEY")
|
|
21
|
+
|
|
22
|
+
const { data, error } = await talkey.sms.send({
|
|
23
|
+
to: ["+237655377730"],
|
|
24
|
+
message: "Hello 👋"
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
console.log(data,error)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## ✉️ Send SMS
|
|
33
|
+
|
|
34
|
+
### Simple SMS
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
await talkey.sms.send({
|
|
38
|
+
to: ["+2376XXXXXXX"],
|
|
39
|
+
message: "Hello 👋"
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### SMS with template
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
await talkey.sms.send({
|
|
47
|
+
to: ["+2376XXXXXXX"],
|
|
48
|
+
template: "otp",
|
|
49
|
+
variables: {
|
|
50
|
+
code: "1234"
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 💬 Send WhatsApp Message
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
await talkey.whatsapp.send({
|
|
61
|
+
to: ["+2376XXXXXXX"],
|
|
62
|
+
template: "welcome",
|
|
63
|
+
variables: {
|
|
64
|
+
name: "Yannick"
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 📥 Response Format
|
|
72
|
+
|
|
73
|
+
### Success
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"messageid": "uuid",
|
|
78
|
+
"data": [
|
|
79
|
+
{
|
|
80
|
+
"success": true,
|
|
81
|
+
"mobile": "+2376XXXXXXX"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"cost": 20
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
### Error
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"messageid": "uuid",
|
|
95
|
+
"code": "INSUFFICIENT_CREDITS",
|
|
96
|
+
"message": "You do not have enough credits to send this SMS."
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 🧠 Error Handling
|
|
103
|
+
|
|
104
|
+
Talkey does not throw errors.
|
|
105
|
+
All responses follow this pattern:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const { data, error } = await talkey.sms.send(...)
|
|
109
|
+
|
|
110
|
+
if (error) {
|
|
111
|
+
// handle error
|
|
112
|
+
} else {
|
|
113
|
+
// use data
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## 📚 Types
|
|
120
|
+
|
|
121
|
+
The SDK includes built-in TypeScript types for better autocomplete and developer experience.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 🔐 API Key
|
|
126
|
+
|
|
127
|
+
You can get your API key from your Talkey dashboard.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 🌍 Supported Channels
|
|
132
|
+
|
|
133
|
+
* SMS (text & template)
|
|
134
|
+
* WhatsApp (template)
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 🚀 Example
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const { data, error } = await talkey.sms.send({
|
|
142
|
+
to: ["+237655377730"],
|
|
143
|
+
template: "otp",
|
|
144
|
+
variables: {
|
|
145
|
+
code: "1234"
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
if (error) {
|
|
150
|
+
console.error(error)
|
|
151
|
+
} else {
|
|
152
|
+
console.log("Message sent:", data.messageid)
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 📄 License
|
|
159
|
+
|
|
160
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type sms = {
|
|
2
|
+
to: string[];
|
|
3
|
+
message?: string;
|
|
4
|
+
template?: string;
|
|
5
|
+
variables?: Record<string, string | number>;
|
|
6
|
+
};
|
|
7
|
+
type whatsapp = {
|
|
8
|
+
to: string[];
|
|
9
|
+
template: string;
|
|
10
|
+
variables?: Record<string, string | number>;
|
|
11
|
+
};
|
|
12
|
+
type data = {
|
|
13
|
+
success: boolean;
|
|
14
|
+
mobile: string;
|
|
15
|
+
};
|
|
16
|
+
type result = {
|
|
17
|
+
messageid: string;
|
|
18
|
+
data: data[];
|
|
19
|
+
cost: number;
|
|
20
|
+
};
|
|
21
|
+
type APIerror = {
|
|
22
|
+
messageid: string;
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare class Client {
|
|
28
|
+
private apiKey;
|
|
29
|
+
private baseUrl;
|
|
30
|
+
constructor(apiKey: string);
|
|
31
|
+
request<T>(method: string, endpoint: string, data?: any): Promise<{
|
|
32
|
+
data?: T;
|
|
33
|
+
error?: APIerror;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
declare class SMS {
|
|
38
|
+
private client;
|
|
39
|
+
constructor(client: Client);
|
|
40
|
+
send(data: sms): Promise<{
|
|
41
|
+
data?: result;
|
|
42
|
+
error?: APIerror;
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare class WhatsApp {
|
|
47
|
+
private client;
|
|
48
|
+
constructor(client: Client);
|
|
49
|
+
send(data: whatsapp): Promise<{
|
|
50
|
+
data?: result;
|
|
51
|
+
error?: APIerror;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
declare class Talkey {
|
|
56
|
+
sms: SMS;
|
|
57
|
+
whatsapp: WhatsApp;
|
|
58
|
+
constructor(apiKey: string);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { type APIerror, Talkey, type data, type result, type sms, type whatsapp };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var Client = class {
|
|
3
|
+
apiKey;
|
|
4
|
+
baseUrl = "https://api.talkey.dev";
|
|
5
|
+
constructor(apiKey) {
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
}
|
|
8
|
+
async request(method, endpoint, data) {
|
|
9
|
+
const res = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
10
|
+
method,
|
|
11
|
+
headers: {
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
14
|
+
},
|
|
15
|
+
body: data ? JSON.stringify(data) : null
|
|
16
|
+
});
|
|
17
|
+
const json = await res.json();
|
|
18
|
+
if (json.error) {
|
|
19
|
+
return { error: json.error };
|
|
20
|
+
}
|
|
21
|
+
return { data: json };
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/resources/sms.ts
|
|
26
|
+
var SMS = class {
|
|
27
|
+
constructor(client) {
|
|
28
|
+
this.client = client;
|
|
29
|
+
}
|
|
30
|
+
async send(data) {
|
|
31
|
+
return this.client.request(
|
|
32
|
+
"POST",
|
|
33
|
+
"/v1/sms",
|
|
34
|
+
{
|
|
35
|
+
...data,
|
|
36
|
+
type: data.template ? "template" : "text"
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/resources/whatsapp.ts
|
|
43
|
+
var WhatsApp = class {
|
|
44
|
+
constructor(client) {
|
|
45
|
+
this.client = client;
|
|
46
|
+
}
|
|
47
|
+
async send(data) {
|
|
48
|
+
return this.client.request(
|
|
49
|
+
"POST",
|
|
50
|
+
"/v1/whatsapp",
|
|
51
|
+
data
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/index.ts
|
|
57
|
+
var Talkey = class {
|
|
58
|
+
sms;
|
|
59
|
+
whatsapp;
|
|
60
|
+
constructor(apiKey) {
|
|
61
|
+
const client = new Client(apiKey);
|
|
62
|
+
this.sms = new SMS(client);
|
|
63
|
+
this.whatsapp = new WhatsApp(client);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
export {
|
|
67
|
+
Talkey
|
|
68
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@talkey/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Talkey SDK",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "Nitcheu Yannick",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files":["/dist", "README.md"],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup src/index.ts --format esm --dts"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"tsup": "^8.5.1",
|
|
16
|
+
"typescript": "^5.9.3"
|
|
17
|
+
}
|
|
18
|
+
}
|