wechaty-puppet-padplus
Version:
Puppet Padplus for Wechaty
152 lines • 6.46 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 config_1 = require("../../config");
const PadPlusServer_pb_1 = require("../../server-manager/proto-ts/PadPlusServer_pb");
const PRE = 'PadplusContact';
class PadplusContact {
constructor(requestClient) {
// Query contact list info
this.getContactInfo = (userName) => __awaiter(this, void 0, void 0, function* () {
config_1.log.verbose(PRE, `getContactInfo(${userName})`);
const data = {
userName,
};
yield this.requestClient.request({
apiType: PadPlusServer_pb_1.ApiType.GET_CONTACT,
data,
});
return true;
});
this.searchContact = (contactId) => __awaiter(this, void 0, void 0, function* () {
config_1.log.verbose(PRE, `searchContact(${contactId})`);
const data = {
wxid: contactId,
};
const result = yield this.requestClient.request({
apiType: PadPlusServer_pb_1.ApiType.SEARCH_CONTACT,
data,
});
if (result) {
const contactStr = result.getData();
if (contactStr) {
return JSON.parse(contactStr);
}
else {
throw new Error(`can not parse data`);
}
}
else {
throw new Error(`can not get callback result`);
}
});
// Set alias for contact
this.setAlias = (contactId, alias) => __awaiter(this, void 0, void 0, function* () {
config_1.log.verbose(PRE, `setAlias()`);
const data = {
newRemarkName: alias,
userName: contactId,
};
yield this.requestClient.request({
apiType: PadPlusServer_pb_1.ApiType.CONTACT_ALIAS,
data,
});
return true;
});
this.syncContacts = () => __awaiter(this, void 0, void 0, function* () {
config_1.log.verbose(PRE, `syncContacts()`);
yield this.requestClient.request({
apiType: PadPlusServer_pb_1.ApiType.SYNC_CONTACT,
});
});
this.contactSelfQrcode = () => __awaiter(this, void 0, void 0, function* () {
config_1.log.verbose(PRE, `contactSelfQrcode()`);
const data = {
style: 0,
type: 1,
};
const result = yield this.requestClient.request({
apiType: PadPlusServer_pb_1.ApiType.GET_CONTACT_SELF_QRCODE,
data,
});
if (result) {
const contactQrcodeStr = result.getData();
if (contactQrcodeStr) {
const contactQrcode = JSON.parse(contactQrcodeStr);
if (contactQrcode.status === 0) {
return contactQrcode.qrcodeBuf;
}
else {
throw new Error(`Can not get contact self qrcode buffer.`);
}
}
else {
throw new Error(`can not parse data`);
}
}
else {
throw new Error(`can not get callback result`);
}
});
this.setContactSelfInfo = (data) => __awaiter(this, void 0, void 0, function* () {
config_1.log.verbose(PRE, `setContactSelfInfo()`);
const result = yield this.requestClient.request({
apiType: PadPlusServer_pb_1.ApiType.SET_CONTACT_SELF_INFO,
data,
});
if (result) {
const setContactSelfInfoStr = result.getData();
if (setContactSelfInfoStr) {
const setContactSelfInfoGrpcResponse = JSON.parse(setContactSelfInfoStr);
if (setContactSelfInfoGrpcResponse.status !== 0) {
throw new Error(`Can not set contact self ${Object.keys(data).join(',')}.`);
}
else {
config_1.log.silly(`update info : ${JSON.stringify(setContactSelfInfoGrpcResponse.updateData)}`);
}
}
else {
throw new Error(`can not parse data`);
}
}
else {
throw new Error(`can not get callback result`);
}
});
this.getContactSelfInfo = () => __awaiter(this, void 0, void 0, function* () {
config_1.log.verbose(PRE, `getContactSelfInfo()`);
const result = yield this.requestClient.request({
apiType: PadPlusServer_pb_1.ApiType.GET_CONTACT_SELF_INFO,
});
if (result) {
const getContactSelfInfoStr = result.getData();
if (getContactSelfInfoStr) {
const getContactSelfInfoGrpcResponse = JSON.parse(getContactSelfInfoStr);
if (getContactSelfInfoGrpcResponse.status !== 0) {
throw new Error(`Can not get contact self info.`);
}
else {
return getContactSelfInfoGrpcResponse;
}
}
else {
throw new Error(`can not parse data`);
}
}
else {
throw new Error(`can not get callback result`);
}
});
this.requestClient = requestClient;
}
}
exports.PadplusContact = PadplusContact;
//# sourceMappingURL=contact.js.map