wechaty-puppet-padplus
Version:
Puppet Padplus for Wechaty
61 lines • 2.63 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const xml_to_json_1 = require("./xml-to-json");
const config_1 = require("../config");
const is_type_1 = require("./is-type");
function appMessageParser(rawPayload) {
return __awaiter(this, void 0, void 0, function* () {
if (!is_type_1.isPayload(rawPayload)) {
return null;
}
const content = rawPayload.content.trim();
let tryXmlText = content;
if (!/^<msg>.*/.test(content)) {
tryXmlText = content.replace(/^[^\n]+\n/, '');
}
try {
const jsonPayload = yield xml_to_json_1.xmlToJson(tryXmlText);
const { title, des, url, thumburl, type, md5, recorditem } = jsonPayload.msg.appmsg;
let appattach;
const tmp = jsonPayload.msg.appmsg.appattach;
if (tmp) {
appattach = {
aeskey: tmp.aeskey,
attachid: tmp.attachid,
cdnattachurl: tmp.cdnattachurl,
cdnthumbaeskey: tmp.cdnthumbaeskey,
emoticonmd5: tmp.emoticonmd5,
encryver: (tmp.encryver && parseInt(tmp.encryver, 10)) || 0,
fileext: tmp.fileext,
islargefilemsg: (tmp.islargefilemsg && parseInt(tmp.islargefilemsg, 10)) || 0,
totallen: (tmp.totallen && parseInt(tmp.totallen, 10)) || 0,
};
}
return {
appattach,
des,
md5,
recorditem,
thumburl,
title,
type: parseInt(type, 10),
url,
};
}
catch (e) {
config_1.log.verbose(e.stack);
return null;
}
});
}
exports.appMessageParser = appMessageParser;
//# sourceMappingURL=message-app-payload-parser.js.map