Skip to content

[Dotdigital] Additional actions #3018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

pvpcookie
Copy link
Contributor

What's being changed

we have added 4 new actions:

  1. Send Email Campaign: Sends a marketing email to a contact.
  2. Send SMS: Sends a marketing SMS to a contact.
  3. Send Transactional Email: Sends a transactional email.
  4. Send Transactional SMS: Sends a transactional SMS.

Why it's being changed

We wanted to add the ablility to send email and sms's via the segment io actions system.

Copy link
Contributor

@joe-ayoub-segment joe-ayoub-segment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pvpcookie thanks for the PR.
I've provided feedback - please take a look.
Nothing major, just lots of minor things, repeated in a few places.
Best regards,
Joe

Comment on lines +26 to +31
from: {
label: 'From',
description: 'Enter a custom From name, or leave blank to use a random number. From name format varies by region. [Learn more](https://support.dotdigital.com/en/articles/8199187-sender-ids-and-originators)',
type: 'string',
required: false,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could or should this be a dynamic dropdown list?

}
},
from: {
label: 'From',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
label: 'From',
label: 'From Name',

defaultSubscription: 'type = "track" and event = "Send Transactional SMS"',
fields: {
to: {
label: 'To',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
label: 'To',
label: 'To Phone Number',

},
message: {
label: 'Message',
description: 'The content of the SMS, up to 160 non-encoded characters per message.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the message is more than 160 chars?

Comment on lines +8 to +15
const checkAndCleanMobileNumber = (mobileNumber: string) => {
mobileNumber = mobileNumber.replace(' ', '').replace('-', '')
if (mobileNumber && mobileNumber.startsWith('+')) {
mobileNumber = mobileNumber.replace('+', '')
}

return mobileNumber
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should throw an error if the phone number is invalid.
For example:
throw new PayloadValidationError('Invalid To Phone Number value')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this might be a better check

function removeNonNumeric(mobileNumber: string): string {
  const numericOnly = mobileNumber.replace(/\D+/g, '');
  if (numericOnly.length < MIN_PHONE_NUMBER_CHAR_LENGTH) {
    throw new PayloadValidationError('Invalid To Phone Number value')
  }
  return numericOnly
}

fields: {
email: {
label: 'Email',
description: "If the contact does not exist in your Dotdigital account, the campaign won't be sent.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this field support multiple email addresses or a single address? Can we make this clear?

Comment on lines +87 to +106
try{
const sendCampaignPayload: sendCampaignPayload = {
campaignID: campaignId,
contactIDs: [contactId],
sendDate: sendDate
}
let endpoint = `/v2/campaigns/send`

if(sendTimeOptimised) {
endpoint = `/v2/campaigns/send-time-optimised`
delete sendCampaignPayload.sendDate
}

const response: ModifiedResponse = await this.post(
endpoint, sendCampaignPayload
);
return response;
} catch (error) {
throw error as APIError ?? 'Failed to send campaign';
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the try/catch block around your request.
It should look something like this:

  ```
 const sendCampaignPayload: sendCampaignPayload = {
    campaignID: campaignId,
    contactIDs: [contactId],
    sendDate: sendDate
  }
  let endpoint = `/v2/campaigns/send`

  if(sendTimeOptimised) {
    endpoint = `/v2/campaigns/send-time-optimised`
    delete sendCampaignPayload.sendDate
  }

  const response: ModifiedResponse = await this.post(
    endpoint, sendCampaignPayload
  )
  return response

password: 'api_password'
}

describe('Send sms', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend adding more tests to check for wrong size message body and bad phone numbers.

Comment on lines +22 to +38
try {
const toAddresses = cleanEmails(payload.toAddresses)
const ccAddresses = cleanEmails(payload.ccAddresses)
const bccAddresses = cleanEmails(payload.bccAddresses)
const fromAddress = checkAndCleanEmail(payload.fromAddress)
return await this.post('/v2/email', {
ToAddresses: toAddresses,
CCAddresses: ccAddresses,
BCCAddresses: bccAddresses,
Subject: payload.subject,
FromAddress: fromAddress,
HtmlContent: payload.htmlContent,
PlainTextContent: payload.plainTextContent
})
} catch (error) {
throw (error as APIError) ?? 'Failed to send transactional email'
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the try/catch block. Segment will surface any errors or successes to the customer.
It should look something like this.

      const toAddresses = cleanEmails(payload.toAddresses)
      const ccAddresses = cleanEmails(payload.ccAddresses)
      const bccAddresses = cleanEmails(payload.bccAddresses)
      const fromAddress = checkAndCleanEmail(payload.fromAddress)
      return await this.post('/v2/email', {
        ToAddresses: toAddresses,
        CCAddresses: ccAddresses,
        BCCAddresses: bccAddresses,
        Subject: payload.subject,
        FromAddress: fromAddress,
        HtmlContent: payload.htmlContent,
        PlainTextContent: payload.plainTextContent
      })

Comment on lines +1 to +16
## What's being changed

Lorem ipsum...

## Why it's being changed

Lorem ipsum...

## How to review / test this change

- Lorem
- ipsum

## Notes

Optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file (I wasn't able to figure out what it's for!)

@joe-ayoub-segment
Copy link
Contributor

Also, tests are failing:
image

You can run tests using this command:

yarn cloud test

Also, please run this command and commit the changes
yarn types

Also, please check that there's no errors when you run this command:
yarn validate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants