perf: 使用 await 处理消息发送;模拟扫码登录成功

dev/supplier-email-drawer
LiaoYijun 9 months ago
parent e3b4eda48d
commit 51f46f9da1

@ -48,18 +48,23 @@ function Profile() {
const handelGernaterQR = useCallback(() => {
const phone = loginUser.whatsAppNo
setQRStatus('loading')
fetchQRCode(phone)
.then(r => {
setQRCode(r.result.qr)
setQRStatus('active')
setTimeout(() => {
//
setQRStatus('scanned')
}, 10000);
})
.catch(ex => {
setQRStatus('expired')
console.error(ex)
})
}, [])
const customStatusRender = (info) => {
console.info(info)
switch (info.status) {
case 'expired':
return (
@ -76,6 +81,13 @@ function Profile() {
</p>
</div>
)
case 'loading':
return (
<Space direction="vertical">
<Spin />
<p>Loading...</p>
</Space>
)
case 'scanned':
return (
<div>

@ -51,13 +51,10 @@ const createWhatsApp = async phone => {
const { version, isLatest } = await fetchLatestBaileysVersion();
const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'out');
const sendTextMessage = (whatsAppNo, content) => {
const sendTextMessage = async (whatsAppNo, content) => {
const number = formatPhoneNumber(whatsAppNo);
try {
waSocket.sendMessage(number, { text: content })
.catch(ex => {
console.info('发送文本消息出错', ex)
});
await waSocket.sendMessage(number, { text: content });
} catch (ex) {
waEmitter.emit('message.error', {
messge: '发送文本消息出错',
@ -67,14 +64,11 @@ const createWhatsApp = async phone => {
}
};
const sendImageMessage = (whatsAppNo, imageUrl) => {
const sendImageMessage = async (whatsAppNo, imageUrl) => {
const number = formatPhoneNumber(whatsAppNo);
try {
waSocket.sendMessage(number, {
await waSocket.sendMessage(number, {
image: { url: imageUrl },
})
.catch(ex => {
console.info('发送图片消息出错', ex)
});
} catch (ex) {
waEmitter.emit('message.error', {
@ -239,7 +233,7 @@ const createWhatsApp = async phone => {
},
// https://github.com/WhiskeySockets/Baileys/blob/31bc8ab/src/Utils/generics.ts#L21
// https://github.com/WhiskeySockets/Baileys/blob/31bc8ab4e2c825c0d774875701ed07e20d05bdb6/WAProto/WAProto.proto
browser: Browsers.baileys('WEAR_OS'),//Browsers.ubuntu('IOS_PHONE'),//Browsers.macOS('Desktop'),
browser: Browsers.macOS('SAFARI'),//Browsers.ubuntu('IOS_PHONE'),//Browsers.baileys('WEAR_OS'),
msgRetryCounterCache,
generateHighQualityLinkPreview: false,
syncFullHistory: false,

Loading…
Cancel
Save