77from fbotics .models .payloads .button_template import ButtonTemplatePayload
88from fbotics .models .payloads .generic_template import GenericTemplatePayload
99from fbotics .models .payloads .list_template import ListTemplatePayload
10+ from fbotics .models .payloads .receipt_template import ReceiptTemplatePayload
1011from fbotics .models .payloads .rich_media import RichMediaPayload
1112from fbotics .models .recipient import Recipient
1213
@@ -18,13 +19,13 @@ def __init__(self, page_access_token=None):
1819 self .page_access_token = page_access_token
1920
2021 def send_button_template (
21- self ,
22- recipient_id = None ,
23- user_ref = None ,
24- phone_number = None ,
25- text = None ,
26- quick_replies = None ,
27- buttons = None ,
22+ self ,
23+ recipient_id = None ,
24+ user_ref = None ,
25+ phone_number = None ,
26+ text = None ,
27+ quick_replies = None ,
28+ buttons = None ,
2829 ):
2930 """Sends a button template to the recipient.
3031
@@ -47,12 +48,12 @@ def send_button_template(
4748 return response
4849
4950 def send_generic_template (
50- self ,
51- recipient_id = None ,
52- user_ref = None ,
53- phone_number = None ,
54- elements = None ,
55- quick_replies = None ,
51+ self ,
52+ recipient_id = None ,
53+ user_ref = None ,
54+ phone_number = None ,
55+ elements = None ,
56+ quick_replies = None ,
5657 ):
5758 """Sends a generic template to the recipient.
5859
@@ -75,13 +76,13 @@ def send_generic_template(
7576 return response
7677
7778 def send_list_template (
78- self ,
79- recipient_id = None ,
80- user_ref = None ,
81- phone_number = None ,
82- elements = None ,
83- buttons = None ,
84- quick_replies = None
79+ self ,
80+ recipient_id = None ,
81+ user_ref = None ,
82+ phone_number = None ,
83+ elements = None ,
84+ buttons = None ,
85+ quick_replies = None ,
8586 ):
8687 """Sends a list template to the recipient.
8788
@@ -104,13 +105,67 @@ def send_list_template(
104105 response = self ._post (message , recipient_id , user_ref , phone_number )
105106 return response
106107
108+ def send_receipt_template (
109+ self ,
110+ recipient_id = None ,
111+ user_ref = None ,
112+ phone_number = None ,
113+ recipient_name = None ,
114+ elements = None ,
115+ order_number = None ,
116+ currency = None ,
117+ payment_method = None ,
118+ timestamp = None ,
119+ address = None ,
120+ summary = None ,
121+ adjustments = None ,
122+ quick_replies = None ,
123+ ):
124+ """Sends a receipt template to the recipient.
125+
126+ # Arguments
127+ recipient_id: page specific id of the recipient
128+ user_ref: optional. user_ref from the checkbox plugin
129+ phone_number: Optional. Phone number of the recipient with the format +1(212)555-2368. Your bot must be approved for Customer Matching to send messages this way.
130+ elements: Optional. Array of a maximum of 100 element objects that describe items in the order. Sort order of the elements is not guaranteed.
131+ order_number: The order number. Must be unique.
132+ currency: The currency of the payment.
133+ payment_method: The payment method used. Providing enough information for the customer to decipher which payment method and account they used is recommended. This can be a custom string, such as, "Visa 1234".
134+ timestamp: Optional. Timestamp of the order in seconds.
135+ address: Optional. The shipping address of the order.
136+ summary: The payment summary.
137+ adjustments: Optional. An array of payment objects that describe payment adjustments, such as discounts.
138+ quick_replies: An array of objects the describe the quick reply buttons to send. A maximum of 11 quick replies are supported.
139+
140+ """
141+
142+ receipt_template_payload = ReceiptTemplatePayload (
143+ dict (
144+ template_type = "receipt" ,
145+ recipient_name = recipient_name ,
146+ elements = elements ,
147+ order_number = order_number ,
148+ currency = currency ,
149+ payment_method = payment_method ,
150+ timestamp = timestamp ,
151+ address = address ,
152+ summary = summary ,
153+ adjustments = adjustments ,
154+ )
155+ )
156+ attachment = Attachment (dict (type = "template" , payload = receipt_template_payload ))
157+ message = Message ({"quick_replies" : quick_replies , "attachment" : attachment })
158+
159+ response = self ._post (message , recipient_id , user_ref , phone_number )
160+ return response
161+
107162 def send_quick_replies (
108- self ,
109- recipient_id = None ,
110- user_ref = None ,
111- phone_number = None ,
112- text = None ,
113- quick_replies = None ,
163+ self ,
164+ recipient_id = None ,
165+ user_ref = None ,
166+ phone_number = None ,
167+ text = None ,
168+ quick_replies = None ,
114169 ):
115170 """Sends quick replies to the recipient.
116171
@@ -147,12 +202,12 @@ def send_text(self, recipient_id=None, user_ref=None, phone_number=None, text=No
147202 return response
148203
149204 def send_image (
150- self ,
151- recipient_id = None ,
152- user_ref = None ,
153- phone_number = None ,
154- url = None ,
155- quick_replies = None ,
205+ self ,
206+ recipient_id = None ,
207+ user_ref = None ,
208+ phone_number = None ,
209+ url = None ,
210+ quick_replies = None ,
156211 ):
157212 """Sends an image to the recipient.
158213
@@ -171,12 +226,12 @@ def send_image(
171226 return response
172227
173228 def send_audio (
174- self ,
175- recipient_id = None ,
176- user_ref = None ,
177- phone_number = None ,
178- url = None ,
179- quick_replies = None ,
229+ self ,
230+ recipient_id = None ,
231+ user_ref = None ,
232+ phone_number = None ,
233+ url = None ,
234+ quick_replies = None ,
180235 ):
181236 """Sends an audio to the recipient.
182237
@@ -195,12 +250,12 @@ def send_audio(
195250 return response
196251
197252 def send_file (
198- self ,
199- recipient_id = None ,
200- user_ref = None ,
201- phone_number = None ,
202- url = None ,
203- quick_replies = None ,
253+ self ,
254+ recipient_id = None ,
255+ user_ref = None ,
256+ phone_number = None ,
257+ url = None ,
258+ quick_replies = None ,
204259 ):
205260 """Sends a file to the recipient.
206261
@@ -241,8 +296,8 @@ def _post(self, message, recipient_id=None, user_ref=None, phone_number=None):
241296 response = requests .post (API_URL , params = params , json = request .to_primitive ())
242297 json_response = response .json ()
243298 if (
244- response .status_code == 400
245- and json_response .get ("error" , {}).get ("type" , "" ) == "OAuthException"
299+ response .status_code == 400
300+ and json_response .get ("error" , {}).get ("type" , "" ) == "OAuthException"
246301 ):
247302 raise OAuthException (json_response .get ("error" ).get ("message" , "" ))
248303 return response
0 commit comments