* Get the talker of a message. * @returns {Contact} * @example * const bot = new Wechaty() * bot * .on('message', async m => { * const talker = msg.talker() * const text = msg.text() * const room = msg.room() * if (room) { * const topic = await room.topic()
()
| 252 | * .start() |
| 253 | */ |
| 254 | public talker (): Contact { |
| 255 | if (!this.payload) { |
| 256 | throw new Error('no payload') |
| 257 | } |
| 258 | |
| 259 | // if (contact) { |
| 260 | // this.payload.from = contact |
| 261 | // return |
| 262 | // } |
| 263 | |
| 264 | const fromId = this.payload.fromId |
| 265 | if (!fromId) { |
| 266 | // Huan(202011): It seems that the fromId will never be null? |
| 267 | // return null |
| 268 | throw new Error('payload.fromId is null?') |
| 269 | } |
| 270 | |
| 271 | const from = this.wechaty.Contact.load(fromId) |
| 272 | return from |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Use `message.talker()` to replace `message.from()` #2094 |
no test coverage detected