send.js 1.33 KB
/**
 * 消息发送
 * @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() {
    if (chat.isOpen()) {
        conMSG.type = recTypes.EVAL_NOTICE;
        _send(conMSG);
    }
};

/**
 * 人工客服
 */
exports.manual = function() {
    conMSG.type = recTypes.MANUAL_SERVICE;
    _send(conMSG);
};