-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
54 lines (41 loc) · 1.7 KB
/
example.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
//add tag and set star on message with id "messageid"
function setTagAndFlag(messageid) {
return new Promise(resolve => {
//Returns a Promise fulfilled with: array of MessageTag
messenger.messages.listTags()
.then(response => {
console.log("messenger.messages.listTags() response:", response);
//check if "newtag" exists, if not add it to tag list
function checkTagKey(tag) {
return tag.key == this;
}
if (!response.find(checkTagKey, "newtag")) {
var newMessageTag = {
color: "black",
key: "newtag", // Distinct tag identifier - use this string when referring to a tag
tag: "newtag", //Human-readable tag name
ordinal: ""
};
//add new tag to the tag list
messenger.tagservice.AddTag(newMessageTag);
}
var newTags = ["kontaktdb", "archiv"];
var newProperties = {
flagged: true, //flagged sets the "star"
tags: newTags
};
try {
messenger.messages.update(messageid, newProperties);
}
catch (error) {
console.error("messenger.messages.update() failed with error:", error);
throw error;
}
resolve(true);
})
.catch(error => {
console.error("messenger.messages.listTags() failed with error:", error);
throw error;
});
});
}