Slack: Fallback missing user name and last name in message (#219)

* Slack: Fallback missing user name and lastname in message

* Slack: Add billing address and user email
This commit is contained in:
Lukasz Ostrowski 2023-02-28 09:52:33 +01:00 committed by GitHub
parent 4e4257d788
commit e746cf9af4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 2 deletions

View file

@ -0,0 +1,6 @@
---
"saleor-app-slack": patch
---
Fix problem with "undefined" user's name & last name in case they are not available.
Introduces "n/a" fallback

View file

@ -0,0 +1,5 @@
---
"saleor-app-slack": minor
---
Billing address is now also included into Slack message. Additonally user emails is always defined

View file

@ -9,9 +9,27 @@ export const sendSlackMessage = async (
) => { ) => {
const { const {
saleorDomain, saleorDomain,
order: { id, number, user, shippingAddress, subtotal, shippingPrice, total }, order: {
id,
number,
user,
shippingAddress,
subtotal,
shippingPrice,
total,
billingAddress,
userEmail,
},
} = data; } = data;
const getCustomerName = () => {
if (user?.firstName && user?.lastName) {
return `${user.firstName} ${user.lastName}`;
} else {
return `n/a`;
}
};
const response = await fetch(to, { const response = await fetch(to, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -27,7 +45,7 @@ export const sendSlackMessage = async (
type: "section", type: "section",
text: { text: {
type: "mrkdwn", type: "mrkdwn",
text: `*Customer*\n${user?.firstName} ${user?.lastName}\n${user?.email}`, text: `*Customer*\n${getCustomerName()}\nEmail: ${userEmail}`,
}, },
}, },
{ {
@ -37,6 +55,13 @@ export const sendSlackMessage = async (
text: `*Shipping Address*\n${shippingAddress?.streetAddress1}\n${shippingAddress?.postalCode} ${shippingAddress?.city}\n${shippingAddress?.country.country}`, text: `*Shipping Address*\n${shippingAddress?.streetAddress1}\n${shippingAddress?.postalCode} ${shippingAddress?.city}\n${shippingAddress?.country.country}`,
}, },
}, },
{
type: "section",
text: {
type: "mrkdwn",
text: `*Billing Address*\n${billingAddress?.streetAddress1}\n${billingAddress?.postalCode} ${billingAddress?.city}\n${billingAddress?.country.country}`,
},
},
{ {
type: "section", type: "section",
text: { text: {

View file

@ -10,6 +10,7 @@ import { sendSlackMessage } from "../../../lib/slack";
const OrderCreatedWebhookPayload = gql` const OrderCreatedWebhookPayload = gql`
fragment OrderCreatedWebhookPayload on OrderCreated { fragment OrderCreatedWebhookPayload on OrderCreated {
order { order {
userEmail
id id
number number
user { user {
@ -25,6 +26,14 @@ const OrderCreatedWebhookPayload = gql`
country country
} }
} }
billingAddress {
streetAddress1
city
postalCode
country {
country
}
}
subtotal { subtotal {
gross { gross {
amount amount