-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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(providers): Add Whatsapp business as provider #5232
feat(providers): Add Whatsapp business as provider #5232
Conversation
✅ Deploy Preview for dev-web-novu ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@vitoorgomes Thanks for bringing this to our attention, we will take a look at it as soon as we can! |
@vitoorgomes What are the other improvements you think could be done? |
Meta's API docs have lots of options to send a message, with media, location and so on, but since they don't affect the usability as of right now, I've decided to not try to implement it, because it would need a lot effort to be able to define each property but could be done in the future as devs request |
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.
@vitoorgomes There is two things you need to fix here.
- The hard coded authentication header
- adding the whatsapp names to the cspell list
017f3d0
to
4f0343b
Compare
done |
✅ Deploy Preview for novu-design ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
providers/whatsapp-business/src/lib/whatsapp-business.provider.spec.ts
Dismissed
Show dismissed
Hide dismissed
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.
Thanks for the hard work here, Vitor! Added a couple comments regarding CI and to ensure we have good handling around phone numbers.
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.
Please consider a more semantic name for the file: whatsapp-message-type.ts
channelType = ChannelTypeEnum.SMS as ChannelTypeEnum.SMS; | ||
|
||
private readonly axiosClient: AxiosInstance; | ||
private readonly baseUrl = 'https://graph.facebook.com/v18.0/'; |
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.
❔ question: Is this correct?
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.
Yep. tested it out.
@@ -1120,3 +1120,21 @@ export const eazySmsConfig: IConfigCredentials[] = [ | |||
description: 'Your SMS Channel Id', | |||
}, | |||
]; | |||
|
|||
export const whatsaAppBusinessConfig: IConfigCredentials[] = [ |
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.
☑ chore: Please correct this typo
export const whatsaAppBusinessConfig: IConfigCredentials[] = [ | |
export const whatsAppBusinessConfig: IConfigCredentials[] = [ |
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.
Fixed
{ | ||
key: CredentialsKeyEnum.phoneNumberIdentification, | ||
displayName: 'Phone Number Identification', | ||
description: 'Your WhatsApp Business phone number identification', |
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.
❓ question: What are the phone number requirements for WhatsApp? Do they require a certain format?
☑ chore: If there is a format required, please describe / define it here, and enforce it with pattern matching
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.
This is provided in the WhatsApp interface, you can't really control it. The needs to copy paste this. I will add this to the doccs section of the whole process
chatChannels.push({ | ||
providerId: ChatProviderIdEnum.WhatsAppBusiness, | ||
credentials: { | ||
phoneNumber: phone, | ||
}, | ||
}); |
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.
I don't love this implementation, but until we refactor the whole "Chat" channel flow, this workaround is needed.
const channelSpecification = subscriberChannel.credentials?.channel; | ||
|
||
if (!chatWebhookUrl) { | ||
if (!chatWebhookUrl && integration.providerId !== ChatProviderIdEnum.WhatsAppBusiness) { |
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.
Those workaround will be handeled during a more thorough refactoring of the "Chat" Channel
@@ -26,6 +26,7 @@ export abstract class SendMessageType { | |||
) { | |||
const errorString = | |||
stringifyObject(error?.response?.body) || | |||
stringifyObject(error?.response?.data) || |
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.
This needed to gracefully map axios errors
headers: { | ||
'X-Novu-Custom-Header': 'test-data', | ||
}, |
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.
This fixes a failing test on next branch
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.
Nice!
I've added some comments regarding code structure aiming to isolate the necessary patch for now in dedicated functions that will be easier to refactor in the future.
apps/worker/src/app/workflow/usecases/send-message/send-message-chat.usecase.ts
Outdated
Show resolved
Hide resolved
apps/worker/src/app/workflow/usecases/send-message/send-message-chat.usecase.ts
Show resolved
Hide resolved
@@ -239,8 +267,8 @@ export class SendMessageChat extends SendMessageBase { | |||
}) | |||
); | |||
|
|||
if (chatWebhookUrl && integration) { | |||
await this.sendMessage(chatWebhookUrl, integration, content, message, command, channelSpecification); | |||
if ((chatWebhookUrl && integration) || (phoneNumber && integration)) { |
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.
In an attempt to start defining a naive strategy pattern until we do the proper refactoring, I want to suggest introducing two private methods:
- sendChannelMessageViaWebhookUrl
- sendChannelMessageViaAPIKey
That way, we will ensure that messages created in Mongo have only defined fields per use case and have fewer and shorter if conditions across the file.
The current sendError
can be implemented inside the above two private methods separately for now.
thanks a lot for helping out @scopsy I didn't saw the last request changes notification, totally my bad really happy that this was merged 🥳🤝 |
Thank you @vitoorgomes so much for your contribution ❤️ and sorry it took a while to merge 🙏 |
What change does this PR introduce?
This PR adds the option to use WhatsApp Business as a provider. The requested issue is #1019.
Although there is already a PR opened, I decide to create this fresh one for two main reasons: firstly because I don't think the OP it's working anymore on that based on replies not being answered and secondly because it only implements sending message as a template, where the Meta API allows to send it as a simple text as well, I wanted to give a little more customization to the user.
There some improvements that could be done here, but they aren't breaking changes, so I think it's worth to open this now, like allowing some other configurations like
preview_url
and other fields available in the Meta's API.There is also the #2689 issue, while it's valid, it would be nice to have this provider as a SMS now, and port this later when Chat Providers are able to receive more data following this issue thread updates.
Why was this change needed?
This Closes #1019 and Closes #4128
Other information (Screenshots)