MCPcopy
hub / github.com/wechaty/python-wechaty / say

Method say

src/wechaty/user/message.py:118–188  ·  view source on GitHub ↗

send the message to the conversation envrioment which is source of this message. If this message is from room, so you can send message to this room. If this message is from contact, so you can send message to this contact, not to room. Args: msg: the me

(self, msg: Union[str, Contact, FileBox, UrlLink, MiniProgram],
                  mention_ids: Optional[List[str]] = None)

Source from the content-addressed store, hash-verified

116 return ''.join(message_list)
117
118 async def say(self, msg: Union[str, Contact, FileBox, UrlLink, MiniProgram],
119 mention_ids: Optional[List[str]] = None) -> Optional[Message]:
120 """
121 send the message to the conversation envrioment which is source of this message.
122
123 If this message is from room, so you can send message to this room.
124
125 If this message is from contact, so you can send message to this contact, not to room.
126 Args:
127 msg: the message object which can be type of str/Contact/FileBox/UrlLink/MiniProgram
128 mention_ids: you can send message with `@person`, the only things you should do is to
129 set contact_id to mention_ids.
130 Examples:
131 >>> message.say('hello')
132 >>> message.say(Contact('contact_id'))
133 >>> message.say(FileBox('file_path'))
134 >>> message.say(UrlLink('url'))
135 >>> message.say(MiniProgram('app_id'))
136 Returns:
137 Optional[Message]: if the message is sent successfully, return the message object.
138 """
139 log.info('say() <%s>', msg)
140
141 if not msg:
142 log.error('can"t say nothing')
143 return None
144
145 room = self.room()
146 if room is not None:
147 conversation_id = room.room_id
148 else:
149 talker = self.talker()
150 if talker is None:
151 raise WechatyPayloadError('Message must be from room/contact')
152 conversation_id = talker.contact_id
153
154 # in order to resolve circular dependency problems which is not for
155 # typing, we import some modules locally.
156 # TODO -> this is not good solution, we will fix it later.
157
158 from .url_link import UrlLink
159 from .mini_program import MiniProgram
160
161 if isinstance(msg, str):
162 message_id = await self.puppet.message_send_text(
163 conversation_id=conversation_id,
164 message=msg,
165 mention_ids=mention_ids)
166 elif isinstance(msg, Contact):
167 message_id = await self.puppet.message_send_contact(
168 conversation_id=conversation_id,
169 contact_id=msg.contact_id,
170 )
171 elif isinstance(msg, FileBox):
172 message_id = await self.puppet.message_send_file(
173 conversation_id=conversation_id, file=msg)
174 elif isinstance(msg, UrlLink):
175 message_id = await self.puppet.message_send_url(

Callers

nothing calls this directly

Calls 10

roomMethod · 0.95
talkerMethod · 0.95
loadMethod · 0.95
WechatyPayloadErrorClass · 0.90
message_send_textMethod · 0.80
message_send_contactMethod · 0.80
message_send_fileMethod · 0.80
message_send_urlMethod · 0.80
readyMethod · 0.45

Tested by

no test coverage detected