|
|
|
@ -34,7 +34,7 @@ const createWhatsApp = async phone => {
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
store?.writeToFile(storeFilename);
|
|
|
|
|
}, 10_000);
|
|
|
|
|
const { state, saveCreds } = await useMultiFileAuthState('baileys_auth_info/' + phone);
|
|
|
|
|
const { state, saveCreds } = await useMultiFileAuthState('./baileys_auth_info/' + phone);
|
|
|
|
|
// fetch latest version of WA Web
|
|
|
|
|
const { version, isLatest } = await fetchLatestBaileysVersion();
|
|
|
|
|
const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'out');
|
|
|
|
@ -52,6 +52,7 @@ const createWhatsApp = async phone => {
|
|
|
|
|
|
|
|
|
|
const messageType = Object.keys(msg.message)[0];
|
|
|
|
|
console.log('messageType', messageType);
|
|
|
|
|
// TODO: 待处理图片消息
|
|
|
|
|
|
|
|
|
|
const fromWhatsAppNo = decodeJid(msg.key.remoteJid);
|
|
|
|
|
|
|
|
|
@ -210,13 +211,11 @@ const createWhatsApp = async phone => {
|
|
|
|
|
const sendTextMessageHandler = (event) => {
|
|
|
|
|
const { to: number, externalId, content } = event;
|
|
|
|
|
const jid = encodeJid(number);
|
|
|
|
|
console.info('number: %s; jid: %s: ', number, jid)
|
|
|
|
|
waSocket.sendMessage(
|
|
|
|
|
jid, { text: content }
|
|
|
|
|
).then(msg => {
|
|
|
|
|
externalIdCache.set(msg.key.id, externalId)
|
|
|
|
|
}).catch(ex => {
|
|
|
|
|
console.error('sendMessage.error: ', ex)
|
|
|
|
|
waEmitter.emit('message:updated', {
|
|
|
|
|
id: generateId(),
|
|
|
|
|
externalId,
|
|
|
|
@ -232,7 +231,7 @@ const createWhatsApp = async phone => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
waSocket.ev.on('connection.update', async update => {
|
|
|
|
|
console.log('connection update: ', update);
|
|
|
|
|
|
|
|
|
|
const { connection, lastDisconnect, qr } = update;
|
|
|
|
|
|
|
|
|
|
if (connection === 'close') {
|
|
|
|
@ -257,13 +256,11 @@ const createWhatsApp = async phone => {
|
|
|
|
|
// waEmitter.on('request.' + whatsAppNo + '.send.text', event => {
|
|
|
|
|
// const { to: number, externalId, content } = event;
|
|
|
|
|
// const jid = encodeJid(number);
|
|
|
|
|
// console.info('number: %s; jid: %s: ', number, jid)
|
|
|
|
|
// waSocket.sendMessage(
|
|
|
|
|
// jid, { text: content }
|
|
|
|
|
// ).then(msg => {
|
|
|
|
|
// externalIdCache.set(msg.key.id, externalId)
|
|
|
|
|
// }).catch(ex => {
|
|
|
|
|
// console.error('sendMessage.error: ', ex)
|
|
|
|
|
// waEmitter.emit('message:updated', {
|
|
|
|
|
// id: generateId(),
|
|
|
|
|
// externalId,
|
|
|
|
@ -286,7 +283,6 @@ const createWhatsApp = async phone => {
|
|
|
|
|
).then(msg => {
|
|
|
|
|
externalIdCache.set(msg.key.id, externalId);
|
|
|
|
|
}).catch(ex => {
|
|
|
|
|
console.error('sendMessage.error: ', ex)
|
|
|
|
|
waEmitter.emit('message:updated', {
|
|
|
|
|
id: generateId(),
|
|
|
|
|
externalId,
|
|
|
|
|