Ejemplo n.º 1
0
 async def send_by(
         self,
         *,
         text: str,
         email: Optional[str] = None,
         key: Optional[str] = None,
         blocks: Optional[List[Block]] = None) -> MessageResponse:
     if not (email or key):
         raise ValueError("Either 'email' or 'key' must exist.")
     payload = drop_none({
         'email': email,
         'key': key,
         'text': text,
         'blocks': blocks,
     })
     async with self.client.limiter:
         r = await self.client.http.request(
             url=f'{self.client.base_url}{self.base_path}.send_by',
             method='POST',
             headers=self.client.headers,
             data=json.dumps(payload,
                             default=json_default).encode('utf-8'),
         )
     await self.client._respect_rate_limit(r)
     return MessageResponse.parse_raw(await r.content())
Ejemplo n.º 2
0
 def send(self,
          *,
          conversation_id: int,
          text: str,
          blocks: Optional[List[Block]] = None) -> MessageResponse:
     payload = drop_none({
         'conversation_id': conversation_id,
         'text': text,
         'blocks': blocks,
     })
     with self.client.limiter:
         r = self.client.http.request(
             'POST',
             f'{self.client.base_url}{self.base_path}.send',
             body=json.dumps(payload,
                             default=json_default).encode('utf-8'),
         )
     self.client._respect_rate_limit(r)
     return MessageResponse.parse_raw(r.data)
Ejemplo n.º 3
0
 async def send_by_email(
         self,
         email: str,
         *,
         text: str,
         blocks: Optional[List[Block]] = None) -> MessageResponse:
     payload = drop_none({
         'email': email,
         'text': text,
         'blocks': blocks,
     })
     async with self.client.limiter:
         r = await self.client.http.request(
             url=f'{self.client.base_url}{self.base_path}.send_by_email',
             method='POST',
             headers=self.client.headers,
             data=json.dumps(payload,
                             default=json_default).encode('utf-8'),
         )
     await self.client._respect_rate_limit(r)
     return MessageResponse.parse_raw(await r.content())
Ejemplo n.º 4
0
def test_drop_none():
    assert drop_none({}) == {}
    assert drop_none({'key': 'value', 'nokey': None}) == {'key': 'value'}