Skip to content

Added Functionaility for Custom Attributes and Subscribers API from Attentive #2873

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 1 commit into
base: main
Choose a base branch
from

Conversation

duynguyen100
Copy link

Added functionaility for action destinations to support mappings of Custom Attribute and Subscribers API, Unit tested all passed!

Testing

Include any additional information about the testing you have completed to
ensure your changes behave as expected. For a speedy review, please check
any of the tasks you completed below during your testing.

  • Added unit tests for new functionality
  • Tested end-to-end using the local server
  • [If destination is already live] Tested for backward compatibility of destination. Note: New required fields are a breaking change.
  • [Segmenters] Tested in the staging environment
  • [Segmenters] [If applicable for this change] Tested for regression with Hadron.

@brennan

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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 @duynguyen100 thanks for the PR.

I think I understand what you are intending to do here.
One Action is to append attributes to a user. Another Action is to subscribe a user.
Both of these Actions are invoked with an identify() call.

Are 2 different Actions really needed for this? I'm wondering if a single Action could collect all the user attributes, and would also have a field where the customer can indicate if the user should be subscribed. You could then make 2 calls to your API to update the attributes and to subscribe the user?

Also do these API calls upsert a user?
For example if a user doesn't already exist, will the customAttributes Action create the user before adding the custom attributes to the user? Same question for the subscribers API call.

I'd be happy to discuss these design questions on a call if you can't make the decision yourself.

Please also have a look at the other comments I left inline.

Best regards,
Joe

@@ -73,7 +73,7 @@
"timers-browserify": "^2.0.12",
"ts-jest": "^27.0.7",
"ts-node": "^9.1.1",
"typescript": "4.9.5",
"typescript": "^5.8.3",
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @duynguyen100 - can you undo this change please? This affects the entire solution and it's a file that should be changed.

@@ -15,7 +15,7 @@
},
"typings": "./dist/esm",
"dependencies": {
"@segment/analytics-browser-actions-braze": "^1.85.0",
"@segment/analytics-browser-actions-braze": "^1.86.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @duynguyen100 . Did you mean to change this file? If not can you revert the change to this file please?

@@ -1,6 +1,6 @@
{
"name": "@segment/analytics-browser-actions-braze",
"version": "1.85.0",
"version": "1.86.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @duynguyen100 . Did you mean to change this file? If not can you revert the change to this file please?

@@ -36,7 +36,7 @@
"@types/google-libphonenumber": "^7.4.23",
"@types/jest": "^27.0.0",
"@types/ssh2-sftp-client": "^9.0.0",
"jest": "^27.3.1",
"jest": "^27.5.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @duynguyen100 . Did you mean to change this file? If not can you revert the change to this file please?

"@segment/analytics-browser-actions-braze": "^1.85.0",
"@segment/analytics-browser-actions-braze-cloud-plugins": "^1.85.0",
"@segment/analytics-browser-actions-braze": "^1.86.0",
"@segment/analytics-browser-actions-braze-cloud-plugins": "^1.86.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @duynguyen100 . Did you mean to change this file? If not can you revert the change to this file please?

Comment on lines +11 to +32
userIdentifiers: {
label: 'User Identifiers',
description: 'At least one identifier (phone or email) is required.',
type: 'object',
required: true,
additionalProperties: true,
properties: {
phone: {
label: 'Phone',
description: "The user's phone number in E.164 format.",
type: 'string',
required: false
},
email: {
label: 'Email',
description: "The user's email address.",
type: 'string',
format: 'email',
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.

You could add some default mappings to look for email and phone. In an identify call these would be as follows:

default: {
  phone: { '@path': '$.traits.phone'},
  email: { '@path': '$.traits.email'}
}

}
}
},
subscriptionType: {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this field is limited to 2 different types of inputs, please update it as below. It will only allow payloads through which contain one of these values:

subscriptionType: {
      label: 'Subscription Type',
      description: 'Type of subscription',
      type: 'string',
      required: true,
      choices: [
        {value: "MARKETING", value: "MARKETING"},
        {value: "TRANSACTIONAL", value: "TRANSACTIONAL"}
      ], 
      default: 'MARKETING'
}

Comment on lines +40 to +57
locale: {
label: 'Locale',
description: 'User locale (language and country)',
type: 'object',
required: false,
properties: {
language: {
label: 'Language',
type: 'string',
required: true
},
country: {
label: 'Country',
type: 'string',
required: true
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Segment actually provides the locale of a client side device in most cases. It doesn't do this for server side SKDs though.

The locale data is usually located here in a Segment payload:

$.context.locale

The value usually looks like this: 'en-US', where the first 2 characters are the language and the last 2 characters are the country.

See https://segment.com/docs/connections/spec/common/#context

You could go with a single locale field that collects this value. You could then parse it and use it as you like in the perform() function.

For example:

locale: {
      label: 'Locale',
      description: 'User locale (language and country)',
      type: 'string',
      required:false,
      default: {'@path': '$.context.locale'}
}


const action: ActionDefinition<Settings, Payload> = {
title: 'Custom Attributes',
description: 'Send custom attributes to Attentive.',
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
description: 'Send custom attributes to Attentive.',
description: 'Send Custom Attributes to Attentive.',

},
{
name: 'Subscribe User',
subscribe: 'type = "identify" and traits.phone != null', // Trigger on identify with `subscribed: true`
Copy link
Contributor

Choose a reason for hiding this comment

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

hi @duynguyen100 is the logic here correct?

@joe-ayoub-segment
Copy link
Contributor

hi again @duynguyen100 tried to yarn build the branch and got this error:

  src/destinations/attentive/customAttributes/index.ts(4,10): error TS2724: '"./types"' has no exported member named 'CustomAttribute'. Did you mean 'CustomAttributes'?
  src/destinations/attentive/subscribers/index.ts(4,35): error TS2307: Cannot find module './types' or its corresponding type declarations.

error Command failed with exit code 1.

Can you address this also please?

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.

2 participants