Skip to content

Commit

Permalink
[client] fix send_template return type SentMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
yehuda-lev committed Nov 10, 2024
1 parent 1088681 commit 0053941
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
26 changes: 15 additions & 11 deletions pywa/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1912,7 +1912,7 @@ def send_template(
reply_to_message_id: str | None = None,
tracker: str | CallbackData | None = None,
sender: str | int | None = None,
) -> str:
) -> SentMessage:
"""
Send a template to a WhatsApp user.
Expand All @@ -1924,7 +1924,7 @@ def send_template(
>>> wa = WhatsApp(...)
>>> wa.send_template(
... to='1234567890',
... template=Temp(
... template=Temp(
... name='buy_new_iphone_x',
... language=Temp.Language.ENGLISH_US,
... header=Temp.TextValue(value='15'),
Expand All @@ -1947,7 +1947,7 @@ def send_template(
>>> wa = WhatsApp(...)
>>> wa.send_template(
... to='1234567890',
... template=Temp(
... template=Temp(
... name='auth_with_otp',
... language=Temp.Language.ENGLISH_US,
... buttons=Temp.OTPButtonCode(code='123456'),
Expand Down Expand Up @@ -1997,14 +1997,18 @@ def send_template(
media_type=MessageType.VIDEO,
phone_id=sender,
)
return self.api.send_message(
sender=sender,
to=str(to),
typ="template",
msg=template.to_dict(is_header_url=is_url),
reply_to_message_id=reply_to_message_id,
biz_opaque_callback_data=helpers.resolve_tracker_param(tracker),
)["messages"][0]["id"]
return SentMessage.from_sent_update(
client=self,
update=self.api.send_message(
sender=sender,
to=str(to),
typ="template", # TODO: Use MessageType.TEMPLATE when implemented
msg=template.to_dict(is_header_url=is_url),
reply_to_message_id=reply_to_message_id,
biz_opaque_callback_data=helpers.resolve_tracker_param(tracker),
),
from_phone_id=sender,
)

def create_flow(
self,
Expand Down
4 changes: 2 additions & 2 deletions pywa/types/base_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def reply_template(
template: Template,
quote: bool = False,
tracker: str | CallbackData | None = None,
) -> str:
) -> SentMessage:
"""
Reply to the message with a template.
Expand All @@ -788,7 +788,7 @@ def reply_template(
>>> wa = WhatsApp(...)
>>> wa.send_template(
... to='1234567890',
... template=Temp(
... template=Temp(
... name='buy_new_iphone_x',
... language=Temp.Language.ENGLISH_US,
... header=Temp.TextValue(value='15'),
Expand Down
18 changes: 10 additions & 8 deletions pywa_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ async def send_template(
reply_to_message_id: str | None = None,
tracker: str | CallbackData | None = None,
sender: str | int | None = None,
) -> str:
) -> SentMessage:
"""
Send a template to a WhatsApp user.
Expand All @@ -1701,7 +1701,7 @@ async def send_template(
>>> wa = WhatsApp(...)
>>> wa.send_template(
... to='1234567890',
... template=Temp(
... template=Temp(
... name='buy_new_iphone_x',
... language=Temp.Language.ENGLISH_US,
... header=Temp.TextValue(value='15'),
Expand All @@ -1724,7 +1724,7 @@ async def send_template(
>>> wa = WhatsApp(...)
>>> wa.send_template(
... to='1234567890',
... template=Temp(
... template=Temp(
... name='auth_with_otp',
... language=Temp.Language.ENGLISH_US,
... buttons=Temp.OTPButtonCode(code='123456'),
Expand Down Expand Up @@ -1771,16 +1771,18 @@ async def send_template(
filename=None,
phone_id=sender,
)
return (
await self.api.send_message(
return SentMessage.from_sent_update(
client=self,
update=await self.api.send_message(
sender=sender,
to=str(to),
typ="template",
typ="template", # TODO use MessageType.TEMPLATE when implemented
msg=template.to_dict(is_header_url=is_url),
reply_to_message_id=reply_to_message_id,
biz_opaque_callback_data=helpers.resolve_tracker_param(tracker),
)
)["messages"][0]["id"]
),
from_phone_id=sender,
)

async def create_flow(
self,
Expand Down
2 changes: 1 addition & 1 deletion pywa_async/types/base_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ async def reply_template(
>>> wa = WhatsApp(...)
>>> wa.send_template(
... to='1234567890',
... template=Temp(
... template=Temp(
... name='buy_new_iphone_x',
... language=Temp.Language.ENGLISH_US,
... header=Temp.TextValue(value='15'),
Expand Down

0 comments on commit 0053941

Please sign in to comment.