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

📝 Add env WHATSAPP_CLOUD_API_URL to possible change https://gr… #1170

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

clairton
Copy link
Contributor

@clairton clairton commented Jan 19, 2024

refs #1117

Summary by CodeRabbit

  • Refactor
    • Dynamically construct API URLs for WhatsApp features using environment variables for improved reliability and configurability.
    • Updated sendWhatsAppMessage function to use env.WHATSAPP_CLOUD_API_URL for URL construction, allowing for more dynamic configuration.

Copy link

vercel bot commented Jan 19, 2024

@clairton is attempting to deploy a commit to the Typebot Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jan 19, 2024

Walkthrough

The recent updates involve the integration of an environment variable, WHATSAPP_CLOUD_API_URL, to dynamically set the API URL across different parts of the application. Previously hardcoded URLs have been refactored to use this variable, allowing for more flexibility and easier configuration changes. If the environment variable is not present, the system defaults to a predefined URL.

Changes

File Path Change Summary
.../whatsapp/getPhoneNumber.ts
.../whatsapp/getSystemTokenInfo.ts
.../pages/api/typebots/[typebotId]/whatsapp/media/[mediaId].ts
Functions and endpoint now dynamically construct the API URL using env.WHATSAPP_CLOUD_API_URL, falling back to a default value if the variable is not set.
.../docs/self-hosting/configuration.mdx Added a new parameter WHATSAPP_CLOUD_API_URL with a default value of https://graph.facebook.com to the configuration parameters for testing bots on WhatsApp from the Preview drawer.
.../bot-engine/whatsapp/sendWhatsAppMessage.ts The function now imports the env entity from @typebot.io/env and uses env.WHATSAPP_CLOUD_API_URL in the URL construction instead of a hardcoded value, introducing a dependency on the env module and allowing for more dynamic configuration of the WhatsApp API URL.
.../env/env.ts Added a new configuration variable WHATSAPP_CLOUD_API_URL to the whatsAppEnv object in env.ts, with optional URL validation and a default value of 'https://graph.facebook.com'.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 29bd5f1 and 4085f32.
Files selected for processing (3)
  • apps/builder/src/features/whatsapp/getPhoneNumber.ts (1 hunks)
  • apps/builder/src/features/whatsapp/getSystemTokenInfo.ts (1 hunks)
  • apps/builder/src/pages/api/typebots/[typebotId]/whatsapp/media/[mediaId].ts (1 hunks)
Additional comments: 3
apps/builder/src/features/whatsapp/getPhoneNumber.ts (1)
  • 25-25: The use of process.env.WHATSAPP_CLOUD_API_URL with a fallback to 'https://graph.facebook.com' is implemented correctly. However, ensure that the environment variable is documented and properly configured in all deployment environments to avoid service disruption.
apps/builder/src/features/whatsapp/getSystemTokenInfo.ts (1)
  • 31-31: The dynamic URL construction using process.env.WHATSAPP_CLOUD_API_URL with a fallback is implemented correctly. Ensure that the environment variable is documented and properly configured in all deployment environments to avoid service disruption.
apps/builder/src/pages/api/typebots/[typebotId]/whatsapp/media/[mediaId].ts (1)
  • 64-64: The dynamic URL construction using process.env.WHATSAPP_CLOUD_API_URL with a fallback is implemented correctly. Ensure that the environment variable is documented and properly configured in all deployment environments to avoid service disruption.

@baptisteArno
Copy link
Owner

@clairton Refactored this to use the in-house env lib and to list it in the configuration docs. Let me know if you're OK to merge this

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4085f32 and cd2cc43.
Files selected for processing (6)
  • apps/builder/src/features/whatsapp/getPhoneNumber.ts (2 hunks)
  • apps/builder/src/features/whatsapp/getSystemTokenInfo.ts (2 hunks)
  • apps/builder/src/pages/api/typebots/[typebotId]/whatsapp/media/[mediaId].ts (2 hunks)
  • apps/docs/self-hosting/configuration.mdx (1 hunks)
  • packages/bot-engine/whatsapp/sendWhatsAppMessage.ts (2 hunks)
  • packages/env/env.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • apps/builder/src/features/whatsapp/getPhoneNumber.ts
  • apps/builder/src/features/whatsapp/getSystemTokenInfo.ts
  • apps/builder/src/pages/api/typebots/[typebotId]/whatsapp/media/[mediaId].ts
Additional comments: 4
packages/bot-engine/whatsapp/sendWhatsAppMessage.ts (2)
  • 6-6: The import of env from @typebot.io/env is correct and aligns with the PR objectives to use environment variables for configuration.
  • 20-20: The usage of env.WHATSAPP_CLOUD_API_URL in the URL construction is a good practice for configurability. However, ensure that the env module provides a valid URL and that the application handles cases where the environment variable might be missing or invalid.
packages/env/env.ts (1)
  • 286-290: The addition of WHATSAPP_CLOUD_API_URL with a default value ensures backward compatibility and prevents failures in case the environment variable is not set. This is a good practice.
apps/docs/self-hosting/configuration.mdx (1)
  • 241-247: The documentation update to include WHATSAPP_CLOUD_API_URL is necessary for informing users about the new environment variable. It's important to keep documentation in sync with code changes.

@clairton
Copy link
Contributor Author

@baptisteArno awesome, thank's!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2c20e96 and 11664f7.
Files selected for processing (6)
  • apps/builder/src/features/whatsapp/getPhoneNumber.ts (2 hunks)
  • apps/builder/src/features/whatsapp/getSystemTokenInfo.ts (2 hunks)
  • apps/builder/src/pages/api/typebots/[typebotId]/whatsapp/media/[mediaId].ts (2 hunks)
  • apps/docs/self-hosting/configuration.mdx (1 hunks)
  • packages/bot-engine/whatsapp/sendWhatsAppMessage.ts (2 hunks)
  • packages/env/env.ts (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • apps/builder/src/features/whatsapp/getSystemTokenInfo.ts
  • apps/builder/src/pages/api/typebots/[typebotId]/whatsapp/media/[mediaId].ts
  • apps/docs/self-hosting/configuration.mdx
  • packages/bot-engine/whatsapp/sendWhatsAppMessage.ts
  • packages/env/env.ts
Additional comments: 2
apps/builder/src/features/whatsapp/getPhoneNumber.ts (2)
  • 8-8: Import of env from @typebot.io/env added.

The addition of the { env } import from @typebot.io/env is consistent with the PR's objective to use an environment variable for the WhatsApp Cloud API URL.

  • 26-26: Usage of env.WHATSAPP_CLOUD_API_URL in API URL construction.

The dynamic construction of the API URL using env.WHATSAPP_CLOUD_API_URL is implemented correctly and falls back to a default value if not set, which aligns with the PR's objectives.

@baptisteArno baptisteArno merged commit 6e391b2 into baptisteArno:main Jan 25, 2024
1 of 4 checks passed
baptisteArno added a commit that referenced this pull request Jan 29, 2024
refs #1117 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Refactor**
- Dynamically construct API URLs for WhatsApp features using environment
variables for improved reliability and configurability.
- Updated `sendWhatsAppMessage` function to use
`env.WHATSAPP_CLOUD_API_URL` for URL construction, allowing for more
dynamic configuration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
thercd pushed a commit to thercd/typebot.io that referenced this pull request Feb 2, 2024
…isteArno#1170)

refs baptisteArno#1117 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Refactor**
- Dynamically construct API URLs for WhatsApp features using environment
variables for improved reliability and configurability.
- Updated `sendWhatsAppMessage` function to use
`env.WHATSAPP_CLOUD_API_URL` for URL construction, allowing for more
dynamic configuration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration with Alternative Whatsapp Cloud API(https://github.com/clairton/unoapi-cloud)
2 participants