-
Notifications
You must be signed in to change notification settings - Fork 2
/
soulengine.mjs
81 lines (72 loc) · 2.23 KB
/
soulengine.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Soul, said } from "soul-engine/soul"
//i do this to deploy the lib directly in my python docker thing, but might be better to just use NPM there
//import { Soul, said } from "./node_modules/soul-engine/dist/soul/index.js" //SoulEnvironment
function initSoul(soulId, env, onConnect, onMessage, onLearned) {
console.log("[initSoul] Env:", env);
const soul = new Soul({
soulId: soulId,
organization: "antont",
blueprint: "python",
//environment: env,
//token: "",
//debug: true
})
soul.connect().then(async () => {
console.log("Soul connected");
//console.log(soul);
//soul.dispatch(said("User", "Hi!"))
onConnect();
return soul;
});
//content, perception
/* custom message event, our app uses this kind of thing, and the discord bot served as an example
soul.on("message", async (evt) => { //_metadata
console.log(process.versions.node)
const evt_json = JSON.stringify(evt)
const evt2 = JSON.parse(evt_json)
//console.log("Soul message EVT:", evt2)
const says = await evt.content()
const metadata = evt2.perception._metadata
//const metadata = evt["perception"] //['_metadata']
//console.log("Soul message PARSED:", says, metadata.repliedMessage)
onMessage(says, metadata.repliedMessage)
})
*/
//normal soul-engine chat
soul.on("says", async ({ content }) => {
console.log("Soul says");
const says = await content()
console.log("Soul said:", says)
onMessage(says)
})
soul.on("learnedAboutUser", async ({ content }) => {
console.log("[learnedAboutUser]]");
const learned = await content();
console.log("Learned:", learned);
onLearned(learned);
})
// soul.on("newPerception", (evt) => {
// console.log("PERCEPTION:", evt);
// })
return soul;
}
/*for making a custom event
function messaged(soul, message) {
const msg_data = {
action: "messaged",
content: message.content,
name: message.authorName,
_metadata: {
message: {
id: message.id,
roomId: message.roomId,
authorId: message.authorId,
username: message.authorName
}
}
}
//console.log("Sending Messaged:", msg_data)
soul.dispatch(msg_data);
}
*/
export { initSoul, Soul, said } //messaged