@empireaiorg/econnect 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/LICENSE +21 -0
- package/README.md +79 -0
- package/index.js +148 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Manuel / Empire 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.
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
## @empireaiorg/econnect
|
|
2
|
+
|
|
3
|
+
Official Node.js SDK for **eConnect** — one consistent API for messaging and
|
|
4
|
+
music platforms.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @empireaiorg/econnect
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
const EConnect = require('@empireaiorg/econnect');
|
|
16
|
+
|
|
17
|
+
const eConnect = new EConnect(
|
|
18
|
+
'https://api.empireunion.xyz', // your eConnect base URL
|
|
19
|
+
process.env.ECONNECT_API_KEY // your Empire ID developer key
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Messaging
|
|
23
|
+
await eConnect.messaging.sendText('telegram', chatId, 'Hello!');
|
|
24
|
+
await eConnect.messaging.sendEmail(userId, 'gmail', to, subject, text, html);
|
|
25
|
+
|
|
26
|
+
// Music
|
|
27
|
+
await eConnect.music.play(userId, 'spotify:track:...', 'spotify');
|
|
28
|
+
await eConnect.music.getDevices(userId, 'spotify');
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Two identities in every call
|
|
32
|
+
|
|
33
|
+
- **You (the developer)** — authenticated by your Empire ID key, passed to
|
|
34
|
+
the constructor above.
|
|
35
|
+
- **Your end-user** — identified by whatever `user_id`/`chatId` string you
|
|
36
|
+
pass to each method. Their connected accounts (Spotify, Gmail, etc.) live
|
|
37
|
+
in eConnect's vault — your key never touches their personal tokens.
|
|
38
|
+
|
|
39
|
+
## Messaging methods
|
|
40
|
+
|
|
41
|
+
| Method | Platforms |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `sendText(app, chatId, text)` | telegram, discord, slack |
|
|
44
|
+
| `sendMedia(app, chatId, imageUrl, caption)` | telegram |
|
|
45
|
+
| `sendDocument(app, chatId, documentUrl, caption)` | telegram |
|
|
46
|
+
| `editMessage(app, chatId, messageId, text)` | telegram |
|
|
47
|
+
| `sendEmbed(app, chatId, embed)` | discord |
|
|
48
|
+
| `addReaction(app, chatId, messageId, emoji)` | discord |
|
|
49
|
+
| `updateMessage(app, chatId, ts, text)` | slack |
|
|
50
|
+
| `sendBlocks(app, chatId, blocks, fallbackText)` | slack |
|
|
51
|
+
| `sendEmail(userId, provider, to, subject, text, html?)` | gmail, sendgrid, resend |
|
|
52
|
+
| `getHistory(app, chatId, limit)` | telegram, discord, slack |
|
|
53
|
+
| `deleteMessage(app, chatId, messageId)` | telegram |
|
|
54
|
+
| `addComment(userId, repo, issueNumber, body)` | github |
|
|
55
|
+
| `sendSMS(app, to, text)` | twilio |
|
|
56
|
+
| `sendWhatsApp(app, to, text)` | twilio |
|
|
57
|
+
| `makeCall(app, to, twimlUrl)` | twilio |
|
|
58
|
+
| `getMessageStatus(app, messageSid)` | twilio |
|
|
59
|
+
|
|
60
|
+
## Music methods
|
|
61
|
+
|
|
62
|
+
| Method | Platforms |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `search(userId, query, app)` | spotify, youtube, deezer |
|
|
65
|
+
| `play(userId, uri, app)` | spotify |
|
|
66
|
+
| `pause(userId, app)` | spotify |
|
|
67
|
+
| `skip(userId, app)` | spotify |
|
|
68
|
+
| `getCurrent(userId, app)` | spotify |
|
|
69
|
+
| `getDevices(userId, app)` | spotify |
|
|
70
|
+
| `addToQueue(userId, uri, app)` | spotify |
|
|
71
|
+
|
|
72
|
+
## Full docs
|
|
73
|
+
|
|
74
|
+
See [empireunion.xyz/docs](https://empireunion.xyz/docs) for the full guide,
|
|
75
|
+
including connecting a user's account via OAuth.
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
MIT
|
package/index.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// Pillar 4: The Developer SDK
|
|
2
|
+
class EConnectSDK {
|
|
3
|
+
constructor(apiBaseUrl, developerApiKey) {
|
|
4
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
5
|
+
this.developerApiKey = developerApiKey; // This will now be the Logto JWT
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// --- MESSAGING BLUEPRINT ---
|
|
9
|
+
get messaging() {
|
|
10
|
+
const sdk = this;
|
|
11
|
+
return {
|
|
12
|
+
sendText: async (targetApp, chatId, text) =>
|
|
13
|
+
sdk.executeAction(chatId, 'send_text', { text: text }, targetApp),
|
|
14
|
+
|
|
15
|
+
sendMedia: async (targetApp, chatId, imageUrl, caption = "") =>
|
|
16
|
+
sdk.executeAction(chatId, 'send_media', { imageUrl: imageUrl, caption: caption }, targetApp),
|
|
17
|
+
|
|
18
|
+
sendDocument: async (targetApp, chatId, documentUrl, caption = "") =>
|
|
19
|
+
sdk.executeAction(chatId, 'send_document', { documentUrl: documentUrl, caption: caption }, targetApp),
|
|
20
|
+
|
|
21
|
+
editMessage: async (targetApp, chatId, messageId, text) =>
|
|
22
|
+
sdk.executeAction(chatId, 'edit_message', { messageId: messageId, text: text }, targetApp),
|
|
23
|
+
|
|
24
|
+
sendEmbed: async (targetApp, chatId, embed) =>
|
|
25
|
+
sdk.executeAction(chatId, 'send_embed', { embed: embed }, targetApp),
|
|
26
|
+
|
|
27
|
+
addReaction: async (targetApp, chatId, messageId, emoji) =>
|
|
28
|
+
sdk.executeAction(chatId, 'add_reaction', { messageId: messageId, emoji: emoji }, targetApp),
|
|
29
|
+
|
|
30
|
+
updateMessage: async (targetApp, chatId, ts, text) =>
|
|
31
|
+
sdk.executeAction(chatId, 'update_message', { ts: ts, text: text }, targetApp),
|
|
32
|
+
|
|
33
|
+
sendBlocks: async (targetApp, chatId, blocks, fallbackText = "New message") =>
|
|
34
|
+
sdk.executeAction(chatId, 'send_blocks', { blocks: blocks, fallbackText: fallbackText }, targetApp),
|
|
35
|
+
|
|
36
|
+
sendEmail: async (user_id, provider, toEmail, subject, text, html = null) =>
|
|
37
|
+
sdk.executeAction(user_id, 'send_email', { to: toEmail, subject: subject, text: text, html: html }, provider),
|
|
38
|
+
|
|
39
|
+
getHistory: async (targetApp, chatId, limit = 10) =>
|
|
40
|
+
sdk.executeAction(chatId, 'get_history', { limit: limit }, targetApp),
|
|
41
|
+
|
|
42
|
+
deleteMessage: async (targetApp, chatId, messageId) =>
|
|
43
|
+
sdk.executeAction(chatId, 'delete_message', { messageId: messageId }, targetApp),
|
|
44
|
+
|
|
45
|
+
addComment: async (user_id, repo, issueNumber, body) =>
|
|
46
|
+
sdk.executeAction(user_id, 'add_comment', { repo: repo, issueNumber: issueNumber, body: body }, 'github'),
|
|
47
|
+
|
|
48
|
+
sendSMS: async (targetApp, to, text) =>
|
|
49
|
+
sdk.executeAction(null, 'send_sms', { to: to, text: text }, targetApp),
|
|
50
|
+
|
|
51
|
+
sendWhatsApp: async (targetApp, to, text) =>
|
|
52
|
+
sdk.executeAction(null, 'send_whatsapp', { to: to, text: text }, targetApp),
|
|
53
|
+
|
|
54
|
+
makeCall: async (targetApp, to, twimlUrl) =>
|
|
55
|
+
sdk.executeAction(null, 'make_call', { to: to, twiml_url: twimlUrl }, targetApp),
|
|
56
|
+
|
|
57
|
+
getMessageStatus: async (targetApp, messageSid) =>
|
|
58
|
+
sdk.executeAction(null, 'get_message_status', { messageSid: messageSid }, targetApp),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// --- MUSIC BLUEPRINT ---
|
|
63
|
+
get music() {
|
|
64
|
+
const sdk = this;
|
|
65
|
+
return {
|
|
66
|
+
search: async (userId, query, targetApp) => sdk.executeMusicAction(userId, 'search', { query: query }, targetApp),
|
|
67
|
+
play: async (userId, uri, targetApp) => sdk.executeMusicAction(userId, 'play', { uri: uri }, targetApp),
|
|
68
|
+
pause: async (userId, targetApp) => sdk.executeMusicAction(userId, 'pause', {}, targetApp),
|
|
69
|
+
skip: async (userId, targetApp) => sdk.executeMusicAction(userId, 'skip', {}, targetApp),
|
|
70
|
+
getCurrent: async (userId, targetApp) => sdk.executeMusicAction(userId, 'get_current', {}, targetApp),
|
|
71
|
+
getDevices: async (userId, targetApp) => sdk.executeMusicAction(userId, 'get_devices', {}, targetApp),
|
|
72
|
+
addToQueue: async (userId, uri, targetApp) => sdk.executeMusicAction(userId, 'add_to_queue', { uri: uri }, targetApp)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// --- INTERNAL HELPER: Messaging ---
|
|
77
|
+
async executeAction(chatId, action, payload, targetApp) {
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(`${this.apiBaseUrl}/v1/messaging/execute`, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: {
|
|
82
|
+
'Content-Type': 'application/json',
|
|
83
|
+
'Authorization': `Bearer ${this.developerApiKey}` // <-- UPDATED TO EMPIRE ID FORMAT
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
user_id: chatId,
|
|
87
|
+
action: action,
|
|
88
|
+
payload: payload,
|
|
89
|
+
target_app: targetApp
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
const data = await response.json();
|
|
93
|
+
if (!response.ok) throw new Error(data.error || 'Unknown eConnect error');
|
|
94
|
+
return data;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("❌ eConnect SDK Error:", error.message);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// --- INTERNAL HELPER: Music ---
|
|
102
|
+
async executeMusicAction(userId, action, payload, targetApp) {
|
|
103
|
+
try {
|
|
104
|
+
const response = await fetch(`${this.apiBaseUrl}/v1/music/execute`, {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
headers: {
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
'Authorization': `Bearer ${this.developerApiKey}` // <-- UPDATED TO EMPIRE ID FORMAT
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
user_id: userId,
|
|
112
|
+
action: action,
|
|
113
|
+
payload: payload,
|
|
114
|
+
target_app: targetApp
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
const data = await response.json();
|
|
118
|
+
if (!response.ok) throw new Error(data.error || 'Unknown eConnect error');
|
|
119
|
+
return data;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("❌ eConnect SDK Error:", error.message);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// --- APP DIRECTORY BLUEPRINT ---
|
|
127
|
+
get apps() {
|
|
128
|
+
return {
|
|
129
|
+
getSupported: async () => {
|
|
130
|
+
try {
|
|
131
|
+
const response = await fetch(`${this.apiBaseUrl}/v1/apps/supported`, {
|
|
132
|
+
headers: {
|
|
133
|
+
'Authorization': `Bearer ${this.developerApiKey}` // <-- UPDATED TO EMPIRE ID FORMAT
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
const data = await response.json();
|
|
137
|
+
if (!response.ok) throw new Error(data.error || 'Unknown eConnect error');
|
|
138
|
+
return data;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error("❌ eConnect SDK Error:", error.message);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
module.exports = EConnectSDK;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@empireaiorg/econnect",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Node.js SDK for eConnect — one API for messaging (Telegram, Discord, Slack, Gmail, GitHub, Twilio) and music (Spotify, YouTube Music, Deezer) platforms.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE"
|
|
10
|
+
],
|
|
11
|
+
"keywords": [
|
|
12
|
+
"econnect",
|
|
13
|
+
"empire-ai",
|
|
14
|
+
"sdk",
|
|
15
|
+
"api",
|
|
16
|
+
"messaging",
|
|
17
|
+
"telegram",
|
|
18
|
+
"discord",
|
|
19
|
+
"slack",
|
|
20
|
+
"spotify",
|
|
21
|
+
"twilio"
|
|
22
|
+
],
|
|
23
|
+
"author": "David Manuel",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/davidmaximimanuel/eConnect.git"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://empireunion.xyz",
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
}
|
|
33
|
+
}
|