send.js
1.45 KB
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
/**
* 消息发送
* @author <qi.li@yoho.cn>
* @date 2017/03/13
*/
var uuid = require('uuid');
var chat = require('./chat');
var sockConf = require('./config');
var recTypes = sockConf.recType;
var conMSG = sockConf.conversationMessage;
/**
* 发送
* @param {msg} 消息体
*/
function _send(msg) {
conMSG.uuid = uuid.v4();
chat.send(msg);
}
/**
* 文本发送
*/
exports.text = function(content) {
var TEXT_TYPE = 1; // 文本消息
conMSG.type = recTypes.CU_SEND;
conMSG.chatMessage.content = content;
conMSG.chatMessage.type = TEXT_TYPE;
_send(conMSG);
};
/**
* 图片发送
*/
exports.image = function(path) {
var IMG_TYPE = 2; // 图片消息
conMSG.type = recTypes.CU_SEND;
conMSG.chatMessage.content = path;
conMSG.chatMessage.type = IMG_TYPE;
_send(conMSG);
};
/**
* 订单发送
*/
exports.order = function(content) {
var ORDER_TYPE = 10; // 订单消息
conMSG.type = recTypes.CU_SEND;
conMSG.chatMessage.type = ORDER_TYPE;
conMSG.chatMessage.content = content;
_send(conMSG);
};
/**
* 评价完成
*/
exports.completeEval = function() {
var TEXT_TYPE = 1; // 文本消息
if (chat.isOpen()) {
conMSG.type = recTypes.EVAL_NOTICE;
conMSG.chatMessage.type = TEXT_TYPE;
conMSG.chatMessage.content = '';
_send(conMSG);
}
};
/**
* 人工客服
*/
exports.manual = function() {
conMSG.type = recTypes.MANUAL_SERVICE;
_send(conMSG);
};