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:
parent
4e4257d788
commit
e746cf9af4
4 changed files with 47 additions and 2 deletions
6
.changeset/kind-sheep-jog.md
Normal file
6
.changeset/kind-sheep-jog.md
Normal 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
|
5
.changeset/seven-frogs-return.md
Normal file
5
.changeset/seven-frogs-return.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"saleor-app-slack": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Billing address is now also included into Slack message. Additonally user emails is always defined
|
|
@ -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: {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue