send message to room Args: some_thing: the message content mention_ids: the list of contact id to be mentioned(@) Examples: >>> await room.say('Hello world!') >>> await room.say(file_box) >>> await room.say(contact_
(self,
some_thing: Union[str, Contact,
FileBox, MiniProgram, UrlLink],
mention_ids: Optional[List[str]] = None
)
| 364 | ) |
| 365 | |
| 366 | async def say(self, |
| 367 | some_thing: Union[str, Contact, |
| 368 | FileBox, MiniProgram, UrlLink], |
| 369 | mention_ids: Optional[List[str]] = None |
| 370 | ) -> Union[None, Message]: |
| 371 | """ |
| 372 | send message to room |
| 373 | Args: |
| 374 | some_thing: the message content |
| 375 | mention_ids: the list of contact id to be mentioned(@) |
| 376 | Examples: |
| 377 | >>> await room.say('Hello world!') |
| 378 | >>> await room.say(file_box) |
| 379 | >>> await room.say(contact_card) |
| 380 | >>> await room.say(urlLink) |
| 381 | Returns: |
| 382 | Message: the sent message or None if send failed |
| 383 | """ |
| 384 | log.info('Room say <%s, %s>', some_thing, mention_ids) |
| 385 | |
| 386 | if not some_thing: |
| 387 | log.error('can"t say nothing') |
| 388 | return None |
| 389 | |
| 390 | # we should import UrlLink type locally because of circular dependency |
| 391 | |
| 392 | from wechaty.user.url_link import UrlLink |
| 393 | from wechaty.user.mini_program import MiniProgram |
| 394 | from wechaty.user.contact import Contact |
| 395 | if isinstance(some_thing, str): |
| 396 | if mention_ids: |
| 397 | mention_info = [] |
| 398 | for mention_id in mention_ids: |
| 399 | mention_contact: Contact = self.wechaty.Contact.load(mention_id) |
| 400 | await mention_contact.ready() |
| 401 | name = mention_contact.name |
| 402 | mention_info.append('@' + name) |
| 403 | |
| 404 | mention_text = AT_SEPARATOR.join(mention_info) |
| 405 | some_thing = mention_text + ' ' + some_thing |
| 406 | |
| 407 | msg_id = await self.puppet.message_send_text( |
| 408 | conversation_id=self.room_id, message=some_thing, |
| 409 | mention_ids=mention_ids |
| 410 | ) |
| 411 | elif isinstance(some_thing, FileBox): |
| 412 | msg_id = await self.puppet.message_send_file( |
| 413 | conversation_id=self.room_id, |
| 414 | file=some_thing |
| 415 | ) |
| 416 | elif isinstance(some_thing, Contact): |
| 417 | msg_id = await self.puppet.message_send_contact( |
| 418 | conversation_id=self.room_id, |
| 419 | contact_id=some_thing.contact_id |
| 420 | ) |
| 421 | elif isinstance(some_thing, UrlLink): |
| 422 | msg_id = await self.puppet.message_send_url( |
| 423 | conversation_id=self.room_id, |
nothing calls this directly
no test coverage detected