MCPcopy
hub / github.com/wechaty/wechaty / toContact

Method toContact

src/user/message.ts:989–1005  ·  view source on GitHub ↗

* Get Share Card of the Message * Extract the Contact Card from the Message, and encapsulate it into Contact class * > Tips: * This function is depending on the Puppet Implementation, see [puppet-compatible-table](https://github.com/wechaty/wechaty/wiki/Puppet#3-puppet-compatible-table)

()

Source from the content-addressed store, hash-verified

987 * @returns {Promise<Contact>}
988 */
989 public async toContact (): Promise<Contact> {
990 log.verbose('Message', 'toContact()')
991
992 if (this.type() !== Message.Type.Contact) {
993 throw new Error('message not a ShareCard')
994 }
995
996 const contactId = await this.wechaty.puppet.messageContact(this.id)
997
998 if (!contactId) {
999 throw new Error(`can not get Contact id by message: ${contactId}`)
1000 }
1001
1002 const contact = this.wechaty.Contact.load(contactId)
1003 await contact.ready()
1004 return contact
1005 }
1006
1007 public async toUrlLink (): Promise<UrlLink> {
1008 log.verbose('Message', 'toUrlLink()')

Callers

nothing calls this directly

Calls 3

typeMethod · 0.95
loadMethod · 0.45
readyMethod · 0.45

Tested by

no test coverage detected