Get or set alias of contact. If new_alias is given, it will set alias to new_alias, otherwise return current alias Notes: Setting aliases too often will result in failure (60 times per minute). Args: new_alias: the new alias
(self,
new_alias: Optional[str] = None
)
| 399 | return self.payload.name |
| 400 | |
| 401 | async def alias(self, |
| 402 | new_alias: Optional[str] = None |
| 403 | ) -> Union[None, str]: |
| 404 | """ |
| 405 | Get or set alias of contact. |
| 406 | |
| 407 | If new_alias is given, it will set alias to new_alias, |
| 408 | otherwise return current alias |
| 409 | |
| 410 | Notes: |
| 411 | Setting aliases too often will result in failure (60 times per minute). |
| 412 | |
| 413 | Args: |
| 414 | new_alias: the new alias of contact. |
| 415 | |
| 416 | Returns: |
| 417 | alias: the current alias of contact |
| 418 | """ |
| 419 | log.info('Contact alias <%s>', new_alias) |
| 420 | if not self.is_ready(): |
| 421 | await self.ready() |
| 422 | |
| 423 | if self.payload is None: |
| 424 | raise WechatyPayloadError('can"t load contact payload <%s>' % self) |
| 425 | |
| 426 | try: |
| 427 | alias = await self.puppet.contact_alias(self.contact_id, new_alias) |
| 428 | |
| 429 | # reload the contact payload |
| 430 | await self.ready(force_sync=True) |
| 431 | return alias |
| 432 | # pylint:disable=W0703 |
| 433 | except Exception as exception: |
| 434 | log.info( |
| 435 | 'Contact alias(%s) rejected: %s', |
| 436 | new_alias, str(exception.args)) |
| 437 | return None |
| 438 | |
| 439 | def is_friend(self) -> Optional[bool]: |
| 440 | """ |
nothing calls this directly
no test coverage detected