Integrate Mellowtel in your Electron app
Here you will see how to implement the Mellowtel library in your Electron project. Estimated time to complete: 3-5 minutes.
Requirements
Before you start, make sure that:
- You have an Electron application set up with either JavaScript or TypeScript
- You have a package manager (npm or yarn) installed
- You have a configuration key from the Mellowtel Dashboard
Install npm package
To install the npm package, run the following command in your terminal:
Basic Implementation
There are two ways you can implement the library in your Electron application:
- Using the built-in consent dialog (recommended)
- Creating your own custom consent interface
Option 1: Using Built-in Consent Dialog
First, import the necessary dependencies and initialize Mellowtel in your main process (usually the file called: main.ts
):
Implementing Settings Access
It’s important to provide users with easy access to their Mellowtel settings. You can show the settings dialog using:
Option 2: Custom Consent Interface
If you prefer to create your own consent interface, you can manually manage the opt-in/opt-out process.
Best Practices
- Always initialize Mellowtel after obtaining user consent
- Provide clear access to settings through your application menu or settings page
- Handle opt-in/opt-out states appropriately in your application logic
- Use meaningful reward messages that align with your application’s features
API Reference
The Mellowtel library for Electron provides the following methods. You can use this reference to understand how to interact with the library:
new Mellowtel(configurationKey: string)
Creates a new instance of the Mellowtel client.
requestConsent(window: BrowserWindow, rewardMessage?: string): Promise<boolean>
Shows the built-in consent dialog and returns whether the user opted in.
init(): Promise<void>
Initializes the Mellowtel service. Should be called after obtaining consent.
showConsentSettings(window: BrowserWindow): Promise<void>
Opens the Mellowtel settings dialog.
getOptInStatus(): boolean
Returns the current opt-in status.
optIn(): Promise<void>
Manually opts the user into the service.
optOut(): Promise<void>
Manually opts the user out of the service.
Need help? Join our Discord community for support.