-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
78 lines (70 loc) · 1.52 KB
/
utils.js
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
import { Datastore } from "@google-cloud/datastore";
const datastore = new Datastore();
async function addToCS(room_id, choice) {
const toCSKey = datastore.key("ToCS");
const entity = {
key: toCSKey,
data: [
{
name: "room_id",
value: room_id,
},
{
name: "is_to_cs",
value: choice,
},
],
};
try {
await datastore.save(entity);
console.log(`ToCS ${toCSKey.id} created successfully.`);
} catch (err) {
console.error("ERROR:", err);
}
}
async function addSuccessRate(room_id, feedback) {
const successRateKey = datastore.key("SuccessRate");
const entity = {
key: successRateKey,
data: [
{
name: "room_id",
value: room_id,
},
{
name: "feedback",
value: feedback,
},
],
};
try {
await datastore.save(entity);
console.log(`SuccessRate ${successRateKey.id} created successfully.`);
} catch (err) {
console.error("ERROR:", err);
}
}
async function addMessage(room_id, message) {
const messageKey = datastore.key("Message");
const entity = {
key: messageKey,
data: [
{
name: "room_id",
value: room_id,
},
{
name: "message",
value: message,
excludeFromIndexes: true,
},
],
};
try {
await datastore.save(entity);
console.log(`Message ${messageKey.id} created successfully.`);
} catch (err) {
console.error("ERROR:", err);
}
}
export { addToCS, addSuccessRate, addMessage };