-
Notifications
You must be signed in to change notification settings - Fork 1
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
[DEV-1983][DEV-1986] Add function to subscribe and unsubscribe contact from active campaign list #1257
base: main
Are you sure you want to change the base?
[DEV-1983][DEV-1986] Add function to subscribe and unsubscribe contact from active campaign list #1257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"active-campaign-client": minor | ||
--- | ||
|
||
Add function to subscribe and upsubscribe contact from active campaign list |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||
import { manageListSubscription } from '../../handlers/manageListSubscription'; | ||||||
|
||||||
// remove .skip to run the test, be aware it does real API calls | ||||||
describe('manage list subscription', () => { | ||||||
const cognitoUserId = '66ae52a0-f051-7080-04a1-465b3a4f44cc'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the proper name of this constant cognitoId, cognitoUserId or username? |
||||||
const listName = 'test-webinar-1732097286071'; | ||||||
|
||||||
it('should subscriber the contact to the list', async () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const result = await manageListSubscription( | ||||||
cognitoUserId, | ||||||
listName, | ||||||
'subscribe' | ||||||
); | ||||||
|
||||||
expect(result.statusCode).toBe(200); | ||||||
}); | ||||||
|
||||||
it('should unsubscribe the contact from the list', async () => { | ||||||
const result = await manageListSubscription( | ||||||
cognitoUserId, | ||||||
listName, | ||||||
'unsubscribe' | ||||||
); | ||||||
expect(result.statusCode).toBe(200); | ||||||
}); | ||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { APIGatewayProxyResult } from 'aws-lambda'; | ||
import { acClient } from '../utils/activeCampaignClient'; | ||
|
||
export async function manageListSubscription( | ||
username: string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the proper name of this attribute |
||
listName: string, | ||
action: 'subscribe' | 'unsubscribe' | ||
): Promise<APIGatewayProxyResult> { | ||
try { | ||
const contactId = await acClient.getContactByCognitoId(username); | ||
if (!contactId) { | ||
return { | ||
statusCode: 404, | ||
body: JSON.stringify({ message: 'Contact not found' }), | ||
}; | ||
} | ||
|
||
const listId = await acClient.getListIdByName(listName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the |
||
|
||
if (action == 'subscribe') { | ||
const response = await acClient.addContactToList(contactId, listId); | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(response), | ||
}; | ||
} else { | ||
const response = await acClient.removeContactFromList(contactId, listId); | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(response), | ||
}; | ||
} | ||
} catch (error) { | ||
console.error('Error:', error); | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({ message: 'Internal server error' }), | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What skip?