Skip to content
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

feat: add webhook parser for NetCore (email) #2372

Merged
merged 31 commits into from
Jan 30, 2023

Conversation

abhilipsasahoo03
Copy link
Contributor

What change does this PR introduce?

  • Created webhook parser for NetCore provider (email).

Why was this change needed?

Additional Context

@abhilipsasahoo03
Copy link
Contributor Author

abhilipsasahoo03 commented Dec 27, 2022

@scopsy @davidsoderberg the failing check is due to lack of default case in switch-case statement in netcore.provider.ts file. I'm not sure what to include in the default case! Please let me know and Kindly review.

@abhilipsasahoo03
Copy link
Contributor Author

@p-fernandez please take a look and let me know if any change is required.

@LetItRock
Copy link
Contributor

LetItRock commented Dec 29, 2022

@abhilipsasahoo03 to solve the default case issue you can instead use the object as the map between enums like:

const NET_CORE_STATUS_TO_EMAIL_EVENT = {
   [NetCoreStatusEnum.OPENED]: EmailEventStatusEnum.OPENED,
   [NetCoreStatusEnum.BOUNCED]: EmailEventStatusEnum.BOUNCED,
...
}

and then use it like:

const status = NET_CORE_STATUS_TO_EMAIL_EVENT[body.EVENT];

@abhilipsasahoo03
Copy link
Contributor Author

@abhilipsasahoo03 to solve the default case issue you can instead use the object as the map between enums like:

const NET_CORE_STATUS_TO_EMAIL_EVENT = {
   [NetCoreStatusEnum.OPENED]: EmailEventStatusEnum.OPENED,
   [NetCoreStatusEnum.BOUNCED]: EmailEventStatusEnum.BOUNCED,
...
}

and then use it like:

const status = NET_CORE_STATUS_TO_EMAIL_EVENT[body.EVENT];

@LetItRock The failing Javascript check has been resolved. Thanks for the suggestion, I'll keep that in mind.

Copy link
Contributor

@p-fernandez p-fernandez left a comment

Choose a reason for hiding this comment

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

🌟

providers/netcore/src/lib/netcore.provider.ts Outdated Show resolved Hide resolved
@abhilipsasahoo03
Copy link
Contributor Author

@p-fernandez I've made the changes. Please take a look.

@abhilipsasahoo03
Copy link
Contributor Author

@scopsy @p-fernandez kindly review!

@p-fernandez
Copy link
Contributor

Please add TRANSID inside of the file .cspell.json to pass the spelling integration check. You can do it here:

"varname"

@abhilipsasahoo03
Copy link
Contributor Author

@p-fernandez kindly review!

@p-fernandez
Copy link
Contributor

@p-fernandez kindly review!

The linter for providers integration checks failed:

providers/netcore test: /home/runner/work/novu/novu/providers/netcore/src/lib/netcore.provider.ts
providers/netcore test:    91:22  warning  Unexpected any. Specify a different type       @typescript-eslint/no-explicit-any
providers/netcore test:    91:28  warning  Unexpected any. Specify a different type       @typescript-eslint/no-explicit-any
providers/netcore test:    93:38  error    ["TRANSID"] is better written in dot notation  @typescript-eslint/dot-notation
providers/netcore test:    96:18  error    ["TRANSID"] is better written in dot notation  @typescript-eslint/dot-notation
providers/netcore test:   100:11  warning  Unexpected any. Specify a different type       @typescript-eslint/no-explicit-any
providers/netcore test:   100:17  warning  Unexpected any. Specify a different type       @typescript-eslint/no-explicit-any
providers/netcore test:   104:39  error    ["TRANSID"] is better written in dot notation  @typescript-eslint/dot-notation
providers/netcore test:   111:40  error    ["EVENT"] is better written in dot notation    @typescript-eslint/dot-notation
providers/netcore test:   120:24  error    ["TRANSID"] is better written in dot notation  @typescript-eslint/dot-notation

In the netcore.provider.ts file replace the ocurrences of the object accesses to TRANSID and EVENT like: obj.TRANSID and obj.EVENT so we can solve that problem.

@abhilipsasahoo03
Copy link
Contributor Author

abhilipsasahoo03 commented Jan 3, 2023

@p-fernandez kindly review!

The linter for providers integration checks failed:

providers/netcore test: /home/runner/work/novu/novu/providers/netcore/src/lib/netcore.provider.ts
providers/netcore test:    91:22  warning  Unexpected any. Specify a different type       @typescript-eslint/no-explicit-any
providers/netcore test:    91:28  warning  Unexpected any. Specify a different type       @typescript-eslint/no-explicit-any
providers/netcore test:    93:38  error    ["TRANSID"] is better written in dot notation  @typescript-eslint/dot-notation
providers/netcore test:    96:18  error    ["TRANSID"] is better written in dot notation  @typescript-eslint/dot-notation
providers/netcore test:   100:11  warning  Unexpected any. Specify a different type       @typescript-eslint/no-explicit-any
providers/netcore test:   100:17  warning  Unexpected any. Specify a different type       @typescript-eslint/no-explicit-any
providers/netcore test:   104:39  error    ["TRANSID"] is better written in dot notation  @typescript-eslint/dot-notation
providers/netcore test:   111:40  error    ["EVENT"] is better written in dot notation    @typescript-eslint/dot-notation
providers/netcore test:   120:24  error    ["TRANSID"] is better written in dot notation  @typescript-eslint/dot-notation

In the netcore.provider.ts file replace the ocurrences of the object accesses to TRANSID and EVENT like: obj.TRANSID and obj.EVENT so we can solve that problem.

@p-fernandez just came across that error in the automated test. I suppose it doesn't support bracket notation. I have made the required changes.

@abhilipsasahoo03
Copy link
Contributor Author

@p-fernandez @scopsy please take a look.

@abhilipsasahoo03
Copy link
Contributor Author

@scopsy @p-fernandez @davidsoderberg please take a look

return EmailEventStatusEnum.UNSUBSCRIBED;
case NetCoreStatusEnum.DROPPED:
return EmailEventStatusEnum.DROPPED;
case NetCoreStatusEnum.INVALID:
Copy link
Contributor

Choose a reason for hiding this comment

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

when do this case happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the docs:
All API requests with syntactically incorrect email ids will be treated as Invalid and no further processing will be done on such ids.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm @p-fernandez what do you think of adding an INVALID to our generic email event status enum?

Copy link
Contributor

Choose a reason for hiding this comment

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

Netcore already explains in their documentation that a syntactically incorrect email generates a hard bounce. So I think we should use our BOUNCED status. They might send invalid just to narrow down the case for internal functionalities.
https://netcorecloud.com/tutorials/troubleshoot-email-bounce/#hard-bounce-email


return {
status: status,
date: new Date().toISOString(),
Copy link
Contributor

@davidsoderberg davidsoderberg Jan 10, 2023

Choose a reason for hiding this comment

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

the body does not contain a date we can use?

Copy link
Contributor Author

@abhilipsasahoo03 abhilipsasahoo03 Jan 10, 2023

Choose a reason for hiding this comment

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

Here is a sample webhook from the docs:

[ {
"TRANSID": 15536250111702803, "RESPONSE": " - 2.0.0 (success)",
"EMAIL": "test@gmail.com",
"TIMESTAMP": 1553681625,
"FROMADDRESS": "info@mydomain.com",
"EVENT": "sent",
"MSIZE": 2155,
"X-APIHEADER": "UNIQUEID",
"TAGS": "mytag1"
} ]

we do have a timestamp here but no date.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay then we keep it like you have it now 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

We can use the timestamp and generate the date from it.

Copy link
Contributor Author

@abhilipsasahoo03 abhilipsasahoo03 Jan 24, 2023

Choose a reason for hiding this comment

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

I think we can do that by passing the timestamp to Date(). Correct me if I'm wrong. I'll look into it. :) @p-fernandez

@abhilipsasahoo03
Copy link
Contributor Author

@davidsoderberg @p-fernandez please review! :)

@ghost
Copy link

ghost commented Jan 24, 2023

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@abhilipsasahoo03 abhilipsasahoo03 requested review from davidsoderberg and removed request for p-fernandez January 25, 2023 19:45
Copy link
Contributor

@p-fernandez p-fernandez left a comment

Choose a reason for hiding this comment

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

🌟

@scopsy scopsy merged commit 3207afc into novuhq:next Jan 30, 2023
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.

[NV-1005] - Create webhook parser for NetCore (email)
5 participants