Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PizzaPalace
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheJoeCoder
PizzaPalace
Commits
acd227a5
Verified
Commit
acd227a5
authored
1 year ago
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
[backend] try to improve webhooks
parent
3c0356ab
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
client/pizza_palace.py
+13
-7
13 additions, 7 deletions
client/pizza_palace.py
server/app.py
+17
-6
17 additions, 6 deletions
server/app.py
server/config.py.example
+25
-0
25 additions, 0 deletions
server/config.py.example
with
55 additions
and
13 deletions
client/pizza_palace.py
+
13
−
7
View file @
acd227a5
...
...
@@ -267,10 +267,11 @@ def refresh_cart_items():
row
+=
1
configure_grid
(
cart_frame
)
def
confirm_order
(
address_vars
:
dict
):
global
cart_id
,
cart_key
def
confirm_order
(
addressline1
,
addressline2
,
city
,
postcode
):
global
cart_id
,
cart_key
,
req_cart_items
required_vars
=
[
addressline1
,
city
,
postcode
]
# Check all address fields are filled
for
var
in
address
_vars
:
for
var
in
required
_vars
:
if
(
var
.
get
()
==
""
):
messagebox
.
showerror
(
"
Error
"
,
"
Please fill in all address fields
"
)
return
...
...
@@ -280,11 +281,13 @@ def confirm_order(address_vars: dict):
return
# Join address fields
address
=
""
for
var
in
address_vars
:
address
+=
var
.
get
()
+
"
,
"
address
=
address
[:
-
2
]
address
+=
addressline1
.
get
()
+
"
,
"
address
+=
addressline2
.
get
()
+
"
,
"
address
+=
city
.
get
()
+
"
,
"
address
+=
postcode
.
get
()
# Confirm order
reqjson
=
{
"
id
"
:
cart_id
,
"
key
"
:
cart_key
,
"
address
"
:
address
}
logger
.
debug
(
reqjson
)
res
=
requests
.
post
(
get_endpoint
(
"
/cart/confirmorder
"
),
json
=
reqjson
)
if
(
res
.
status_code
==
200
):
req_cart_items
=
[]
...
...
@@ -292,6 +295,8 @@ def confirm_order(address_vars: dict):
new_session
()
tab_control
.
select
(
order_frame
)
messagebox
.
showinfo
(
"
OK!
"
,
"
Order confirmed
"
)
else
:
messagebox
.
showerror
(
"
Error
"
,
"
Failure to order:
"
+
res
.
text
)
def
tab_changed_handler
(
event
):
selected_tab
=
event
.
widget
.
select
()
...
...
@@ -389,7 +394,8 @@ confirm_label_4.grid(column=1, row=4, sticky=(W, E))
confirm_entry_4
=
ttk
.
Entry
(
confirm_frame
,
width
=
20
,
textvariable
=
confirm_postcode
)
confirm_entry_4
.
grid
(
column
=
2
,
row
=
4
,
sticky
=
(
W
,
E
))
confirm_button_1
=
ttk
.
Button
(
confirm_frame
,
text
=
"
Confirm
"
,
command
=
lambda
:
confirm_order
([
confirm_addressline1
,
confirm_addressline2
,
confirm_city
,
confirm_postcode
]))
confirm_button_1
=
ttk
.
Button
(
confirm_frame
,
text
=
"
Confirm
"
,
command
=
lambda
:
confirm_order
(
confirm_addressline1
,
confirm_addressline2
,
confirm_city
,
confirm_postcode
))
confirm_button_1
.
grid
(
column
=
1
,
row
=
5
,
sticky
=
(
W
,
E
))
# Pack
tab_control
.
pack
(
expand
=
1
,
fill
=
"
both
"
)
...
...
This diff is collapsed.
Click to expand it.
server/app.py
+
17
−
6
View file @
acd227a5
...
...
@@ -211,10 +211,11 @@ def confirm_order_cart():
if
(
address
==
None
):
return
gen_missing_message
(
"
address
"
)
# Test for invalid address and convert to dict
try
:
address
=
json
.
loads
(
address
)
except
:
return
gen_invalid_message
(
"
address
"
)
#print(address)
#try:
# address = json.loads(address)
#except:
# return gen_invalid_message("address")
# Build order
order
=
{
"
address
"
:
address
,
...
...
@@ -224,9 +225,19 @@ def confirm_order_cart():
order_id
=
db
.
orders
.
insert_one
(
order
).
inserted_id
# Post webhook
webhook_data
=
{
"
username
"
:
"
PizzaBot
"
,
"
content
"
:
config
.
webhook_content_prepend
+
str
(
order_id
)
"
username
"
:
"
PizzaBot
"
}
if
config
.
webhook_discord
:
# Post webhook
embed
=
config
.
webhook_dc_embed_json
for
i
in
range
(
0
,
len
(
embed
[
"
fields
"
])):
for
field_k
,
field_v
in
embed
[
"
fields
"
][
i
].
items
():
embed
[
"
fields
"
][
i
][
field_k
]
=
str
(
field_v
).
replace
(
"
%ORDER_ID%
"
,
str
(
order_id
))
embed
[
"
fields
"
][
i
][
field_k
]
=
str
(
field_v
).
replace
(
"
%ADDRESS%
"
,
str
(
address
))
embed
[
"
fields
"
][
i
][
field_k
]
=
str
(
field_v
).
replace
(
"
%ITEMS%
"
,
str
(
cart
[
"
items
"
]))
webhook_data
[
"
embeds
"
]
=
[
embed
]
else
:
webhook_data
[
"
content
"
]
=
config
.
webhook_content_prepend
+
str
(
order_id
)
try
:
webhook_response
=
requests
.
post
(
config
.
webhook_url
,
json
=
webhook_data
)
if
(
webhook_response
.
status_code
!=
200
):
...
...
This diff is collapsed.
Click to expand it.
server/config.py.example
+
25
−
0
View file @
acd227a5
webhook = "https://example.com/webhook"
webhook_content_prepend = "New order received! Order ID: "
webhook_discord = True # If true, will use discord embeds below instead of prepend
webhook_dc_embed_json = {
"author": {
"name": "PizzaPalace"
},
"title": "New Order!",
"fields": [
{
"name": "Order ID",
"value": "%ORDER_ID%"
},
{
"name": "Address",
"value": "%ADDRESS%"
},
{
"name": "Items",
"value": "%ITEMS%"
}
],
"color": "#00b0f4",
"footer": {
"text": "PizzaPalace by TheJoeCoder"
}
}
delivery_flatrate = 0.0
mongo_uri = "mongodb://localhost:27017/"
mongo_db = "pizza_palace"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment