Message
All wechat messages will be encapsulated as a Message.
Message
All wechat messages will be encapsulated as a Message.
Kind: global class
instance
.from() ⇒
Contact
|null
.to() ⇒
Contact
|null
.room() ⇒
Room
|null
.text() ⇒
string
.say(textOrContactOrFile) ⇒
Promise <void>
.type() ⇒
MessageType
.self() ⇒
boolean
.mention() ⇒
Promise <Contact []>
.mentionSelf() ⇒
Promise <boolean>
.forward(to) ⇒
Promise <void>
.date() ⇒
Date
.age() ⇒
number
.toFileBox() ⇒
Promise <FileBox>
.toContact() ⇒
Promise <Contact>
.toUrlLink() ⇒
Promise <UrlLink>
static
.find() ⇒
Promise <Message>
.findAll() ⇒
Promise <Message []>
message.from() ⇒ Contact | null
Contact | null
Get the sender from a message.
Kind: instance method of Message
Example
message.to() ⇒ Contact
| null
Contact
| null
Get the destination of the message Message.to() will return null if a message is in a room, use Message.room() to get the room.
Kind: instance method of Message
Example
message.room() ⇒ Room
| null
Room
| null
Get the room from the message. If the message is not in a room, then will return null
Kind: instance method of Message
Example
message.content()
Deprecated
use text instead
Kind: instance method of Message
message.text() ⇒ string
string
Get the text content of the message
Kind: instance method of Message
Example
message.toRecalled() ⇒ Promise <Message | null>
Promise <Message | null>
Get the text content of the recalled message
Kind: instance method of Message
Example
message.say(textOrContactOrFileOrUrlLinkOrMiniProgram) ⇒ Promise <void>
Promise <void>
Reply a Text, Contact Card, Media File or Link message to the sender.
Tips: This function is depending on the Puppet Implementation, see puppet-compatible-table
Kind: instance method of Message
See: Examples/ding-dong-bot
Param | Type | Description |
textOrContactOrFileOrUrlLinkOrMiniProgram |
| send text, Contact, UrlLink, MiniProgram or file to bot. You can use FileBox to send file |
Example
message.type() ⇒ MessageType
MessageType
Get the type from the message.
Tips: MessageType is Enum here. </br>
MessageType.Unknown
MessageType.Attachment
MessageType.Audio
MessageType.Contact
MessageType.Emoticon
MessageType.Image
MessageType.Text
MessageType.Video
MessageType.Url
Kind: instance method of Message
Example
message.self() ⇒ boolean
boolean
Check if a message is sent by self.
Kind: instance method of Message
Returns: boolean
- - Return true
for send from self, false
for send from others. Example
message.mention() ⇒ Promise <Contact []>
Promise <Contact []>
Get message mentioned contactList.
Message event table as follows
Web | Mac PC Client | iOS Mobile | android Mobile | |
[You were mentioned] tip ([有人@我]的提示) | ✘ | √ | √ | √ |
Identify magic code (8197) by copy & paste in mobile | ✘ | √ | √ | ✘ |
Identify magic code (8197) by programming | ✘ | ✘ | ✘ | ✘ |
Identify two contacts with the same roomAlias by [You were mentioned] tip | ✘ | ✘ | √ | √ |
Kind: instance method of Message
Returns: Promise <Contact []>
- - Return message mentioned contactList Example
message.mentionSelf() ⇒ Promise <boolean>
Promise <boolean>
Check if a message is mention self.
Kind: instance method of Message
Returns: Promise <boolean>
- - Return true
for mention me. Example
message.forward(to) ⇒ Promise <void>
Promise <void>
Forward the received message.
Kind: instance method of Message
Param | Type | Description |
to |
| Room or Contact The recipient of the message, the room, or the contact |
Example
message.date() ⇒ Date
Date
Message sent date
Kind: instance method of Message
message.age() ⇒ number
number
Returns the message age in seconds.
For example, the message is sent at time 8:43:01
, and when we received it in Wechaty, the time is 8:43:15
, then the age() will return 8:43:15 - 8:43:01 = 14 (seconds)
Kind: instance method of Message
message.file()
Deprecated
use toFileBox instead
Kind: instance method of Message
message.toFileBox() ⇒ Promise <FileBox>
Promise <FileBox>
Extract the Media File from the Message, and put it into the FileBox.
Tips: This function is depending on the Puppet Implementation, see puppet-compatible-table
Kind: instance method of Message
message.toContact() ⇒ Promise <Contact>
Promise <Contact>
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
Kind: instance method of Message
message.toUrlLink() ⇒ Promise <UrlLink>
Promise <UrlLink>
Get Url Link of the Message Extract the Url Link from the Message, and encapsulate it into UrlLink class
Tips: This function is depending on the Puppet Implementation, see puppet-compatible-table
Kind: instance method of Message
Message.find() ⇒ Promise <Message | null>
Promise <Message | null>
Find message in cache
Kind: static method of Message
Message.findAll() ⇒ Promise <Message []>
Promise <Message []>
Find messages in cache
Kind: static method of Message
Last updated