forked from fbsamples/whatsapp-business-jaspers-market
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.sh
More file actions
206 lines (191 loc) · 6.97 KB
/
template.sh
File metadata and controls
206 lines (191 loc) · 6.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
# Copyright 2021-present, Facebook, Inc. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
APPTOKEN="<APP_TOKEN>"
APPID="<APP_ID>"
WABAID="<WABA_ID>"
APIVERSION="<CLOUD_API_VERSION>"
echo "Downloading image assets from Meta"
mkdir public
curl -o public/groceries.jpg https://scontent.xx.fbcdn.net/mci_ab/uap/asset_manager/id/?ab_b=e\&ab_page=AssetManagerID\&ab_entry=1530053877871776
curl -o public/salad_bowl.jpg https://scontent.xx.fbcdn.net/mci_ab/uap/asset_manager/id/?ab_b=e\&ab_page=AssetManagerID\&ab_entry=3255815791260974
curl -o public/sheet_pan_dinner.jpg https://scontent.xx.fbcdn.net/mci_ab/uap/asset_manager/id/?ab_b=e\&ab_page=AssetManagerID\&ab_entry=1389202275965231
curl -o public/strawberries.jpg https://scontent.xx.fbcdn.net/mci_ab/uap/asset_manager/id/?ab_b=e\&ab_page=AssetManagerID\&ab_entry=1393969325614091
declare -A handles
for image in "groceries" "salad_bowl" "sheet_pan_dinner" "strawberries"; do
echo "Uploading $image"
file_length=$(stat -f%z "public/$image.jpg")
response=$(curl -s -X POST "https://graph.facebook.com/${APIVERSION}/${APPID}/uploads?file_name=${image}.jpg&file_length=${file_length}&file_type=image/jpg&access_token=${APPTOKEN}")
upload_session_id=$(echo "$response" | jq -r '.id')
echo "Upload session id: $upload_session_id"
upload_response=$(curl -s -X POST "https://graph.facebook.com/${APIVERSION}/${upload_session_id}" \
--header "Authorization: OAuth ${APPTOKEN}" \
--header "file_offset: 0" \
--data-binary @"public/${image}.jpg")
echo "Upload response: $upload_response"
handle=$(echo "$upload_response" | jq -r '.h')
echo "Handle: $handle"
handles["$image"]="$handle"
done
echo "Creating interactive media template"
curl -X POST "https://graph.facebook.com/${APIVERSION}/${WABAID}/message_templates" \
-H "Authorization: Bearer ${APPTOKEN}" \
-H "Content-Type: application/json" \
-d '{
"name": "grocery_delivery_utility",
"language": "en_US",
"category": "marketing",
"components": [
{
"type": "header",
"format": "image",
"example": {
"header_handle": [
"'"${handles["groceries"]}"'"
]
}
},
{
"type": "body",
"text": "Free delivery for all online orders with Jasper’s Market"
},
{
"type": "footer",
"text": "developers.facebook.com"
},
{
"type": "buttons",
"buttons": [
{
"type": "url",
"text": "Get free delivery",
"url": "https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/utility-templates/utility-templates"
}
]
}
]
}'
echo
echo "Creating recipe media carousel template..."
curl -X POST "https://graph.facebook.com/${APIVERSION}/${WABAID}/message_templates" \
-H "Authorization: Bearer ${APPTOKEN}" \
-H "Content-Type: application/json" \
-d '{
"name": "recipe_media_carousel",
"language": "en_US",
"category": "marketing",
"components": [
{
"type": "body",
"text": "Our in-house chefs have prepared some delicious and fresh summer recipes."
},
{
"type": "carousel",
"cards": [
{
"components": [
{
"type": "header",
"format": "image",
"example": {
"header_handle": [
"'"${handles["sheet_pan_dinner"]}"'"
]
}
},
{
"type": "body",
"text": "Simple and Healthy Sheet Pan Dinner to Feed the Whole Family"
},
{
"type": "buttons",
"buttons": [
{
"type": "url",
"text": "Get this recipe",
"url": "https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/marketing-templates/media-card-carousel-templates"
}
]
}
]
},
{
"components": [
{
"type": "header",
"format": "image",
"example": {
"header_handle": [
"'"${handles["salad_bowl"]}"'"
]
}
},
{
"type": "body",
"text": "3 Plant-Powered Salad Bowls to Fuel Your Week"
},
{
"type": "buttons",
"buttons": [
{
"type": "url",
"text": "Get this recipe",
"url": "https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/marketing-templates/media-card-carousel-templates"
}
]
}
]
}
]
}
]
}'
echo
echo "Creating strawberries limited offer template..."
curl -X POST "https://graph.facebook.com/${APIVERSION}/${WABAID}/message_templates" \
-H "Authorization: Bearer ${APPTOKEN}" \
-H "Content-Type: application/json" \
-d '{
"name": "strawberries_limited_offer",
"language": "en_US",
"category": "marketing",
"components": [
{
"type": "header",
"format": "image",
"example": {
"header_handle": [
"'"${handles["strawberries"]}"'"
]
}
},
{
"type": "limited_time_offer",
"limited_time_offer": {
"text": "Expiring offer!",
"has_expiration": true
}
},
{
"type": "body",
"text": "Fresh strawberries at Jasper'\''s Market are now 20% off! Get them while they last"
},
{
"type": "buttons",
"buttons": [
{
"type": "copy_code",
"example": "BERRIES20"
},
{
"type": "url",
"text": "Shop now",
"url": "https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/marketing-templates/limited-time-offer-templates"
}
]
}
]
}'
echo
echo "Finished! Please check for errors if any"