-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Important:Please file the issue follow the template, or we won't help you to solve the problem.
0. Report Issue Guide
- Please run the following command and check whether the problem has been fixed:
rm -rf package-lock.json
rm -rf node_modules
npm install
-
Please search in FAQ List first, and make sure your problem has not been solved before.
-
Please search in the issue first, and make sure your problem had not been reported before
1. Versions
-
What is your wechaty version?
Answer: 0.23.40 -
Which puppet are you using for wechaty? (padchat/puppeteer/padpro/...)
Answer: padpro -
What is your wechaty-puppet-XXX(padchat/puppeteer/) version?
Answer: 0.0.51 -
What is your node version? (run
node --version
)
Answer: 0.15 -
What os are you using
Answer: Mac
2. Describe the bug
When calling room.say()
with an mention contact passed in, it will always add a @XXX
at the beginning of the text
3. To Reproduce
This part is very important: if you can not provide any reproduce steps, then the problem will be very hard to be recognized.
Reproduce code
import { Wechaty, Message } from 'wechaty';
import { generate } from 'qrcode-terminal';
import { PuppetPadpro } from 'wechaty-puppet-padpro';
const YOUR_WXID = 'lylezhuifeng'; // change the id to yours
const puppet = new PuppetPadpro({
token: 'token'
});
const bot = new Wechaty({
name: 'test',
puppet
});
bot
.on('scan', (qrcode, status) => {
generate(qrcode, { small: true })
const qrcodeImageUrl = [
'https://api.qrserver.com/v1/create-qr-code/?data=',
encodeURIComponent(qrcode),
].join('')
console.log(`[${status}] ${qrcodeImageUrl}\nScan QR Code above to log in: `)
})
.on('login', async user => {
console.log(`Login: ${user}`);
})
.on('message', async (message: Message) => {
const room = message.room();
const contact = message.from();
if (room && contact && contact.id === YOUR_WXID) {
const AT_SEPARATOR = String.fromCharCode(8197)
await room.say(`你好啊@${room.alias(contact)}${AT_SEPARATOR}`, contact)
}
})
.start()
4. Expected behavior
Only one @ sign in the text, like 你好啊@高原
, instead of @高原 你好啊@高原
.
5. Actual behavior
Two @ sign appear in the text.
6. Full Output Logs
Set env WECHATY_LOG=silly
in order to set log level to silly, then we can get the full log (If you dosen't set log env, log level is info as default, we cannot get the full log)
The log is not necessary.
7. Additional context
Add any other context about the problem here.
code in wechaty
public async say (
textOrContactOrFileOrUrl : string | Contact | FileBox | UrlLink,
mention? : Contact | Contact[],
): Promise<void> {
let replyToList: Contact[] = []
replyToList = replyToList.concat(mention || [])
const mentionAliasList = await Promise.all(
replyToList.map(
async c => await this.alias(c) || c.name()
)
)
log.verbose('Room', 'say(%s, %s)',
textOrContactOrFileOrUrl,
mentionAliasList.join(', '),
)
let text: string
if (typeof textOrContactOrFileOrUrl === 'string') {
if (mentionAliasList.length > 0) {
// const AT_SEPRATOR = String.fromCharCode(8197)
const AT_SEPRATOR = FOUR_PER_EM_SPACE
const mentionList = mentionAliasList.map(roomAlias => '@' + roomAlias).join(AT_SEPRATOR)
text = mentionList + ' ' + textOrContactOrFileOrUrl
} else {
text = textOrContactOrFileOrUrl
}
const receiver = {
contactId : replyToList.length && replyToList[0].id || undefined,
roomId : this.id,
}
await this.puppet.messageSendText(
receiver,
text,
replyToList.map(c => c.id),
)
} else if (textOrContactOrFileOrUrl instanceof FileBox) {
await this.puppet.messageSendFile({
roomId: this.id,
}, textOrContactOrFileOrUrl)
} else if (textOrContactOrFileOrUrl instanceof Contact) {
await this.puppet.messageSendContact({
roomId: this.id,
}, textOrContactOrFileOrUrl.id)
} else if (textOrContactOrFileOrUrl instanceof UrlLink) {
/**
* 4. Link Message
*/
await this.puppet.messageSendUrl({
contactId : this.id
}, textOrContactOrFileOrUrl.payload)
} else {
throw new Error('arg unsupported: ' + textOrContactOrFileOrUrl)
}
}