UNPKG

2.79 kBJavaScriptView Raw
1var Promise = require('promise');
2var winston = require('./winston');
3
4var Conversation = function(config, single, plural){
5 var request = require('./c21request.js')(config)
6
7 return {
8
9
10 archive: function(recipient_id, user_id){
11
12 var body = {};
13 if (user_id) {
14 body["user_id"] = user_id;
15 }
16 winston.debug("body", body);
17
18 var admintoken = "";
19 if (config.admintoken) {
20 admintoken = "?token=" + encodeURIComponent(config.admintoken);
21 winston.debug("chat21-node-sdk admintoken", admintoken);
22 }
23
24 return new Promise(function(resolve, reject){
25
26 request.delete('/' + plural +'/'+recipient_id+ admintoken, body).then(function(data){
27 winston.debug("chat21-node-sdk conversation.archived", data);
28 resolve(data)
29 }).catch(function(err){
30 winston.debug("chat21-node-sdk conversation.archived", err);
31 reject(err)
32 })
33 })
34 },
35
36
37 typing: function(recipient_id, writer_id, text, timestamp){
38
39 var body = {};
40
41 if (writer_id) {
42 body["writer_id"] = writer_id;
43 }
44
45 if (text) {
46 body["text"] = text;
47 }
48
49 if (timestamp) {
50 body["timestamp"] = timestamp;
51 }
52
53 winston.debug("body", body);
54
55 var admintoken = "";
56 if (config.admintoken) {
57 admintoken = "?token=" + encodeURIComponent(config.admintoken);
58 winston.debug("chat21-node-sdk admintoken", admintoken);
59 }
60
61 return new Promise(function(resolve, reject){
62
63 request.put('/typings/'+recipient_id+ admintoken, body).then(function(data){
64 winston.debug("chat21-node-sdk conversation typing", data);
65 resolve(data)
66 }).catch(function(err){
67 winston.debug("error chat21-node-sdk conversation typing", err);
68 reject(err)
69 })
70 })
71 },
72
73 // deprecated
74 // not in use
75 stopTyping: function(recipient_id, writer_id){
76
77 var body = {};
78 if (writer_id) {
79 body["writer_id"] = writer_id;
80 }
81 winston.debug("body", body);
82
83 var admintoken = "";
84 if (config.admintoken) {
85 admintoken = "?token=" + encodeURIComponent(config.admintoken);
86 winston.debug("chat21-node-sdk admintoken", admintoken);
87 }
88
89 return new Promise(function(resolve, reject){
90
91 request.delete('/typings/'+recipient_id+ admintoken, body).then(function(data){
92 winston.debug("chat21-node-sdk conversation stoptypings", data);
93 resolve(data)
94 }).catch(function(err){
95 winston.debug("error chat21-node-sdk conversation stoptypings", err);
96 reject(err)
97 })
98 })
99 },
100
101
102
103 }
104}
105
106module.exports = Conversation
\No newline at end of file