Integrate Mellowtel into your Windows desktop application to allow users to share their unused internet bandwidth in exchange for rewards or premium features.
User consent is mandatory. The SDK will throw an InvalidOperationException if you call StartAsync() without the user having opted in.
Prerequisites
A Mellowtel account and configuration key (get yours from the dashboard )
A NuGet access token provided by Mellowtel (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)
.NET desktop application (Console, WPF, or Windows Forms)
Installation
Create a file named nuget.config in your project’s root directory (the same folder as your .csproj or .sln file):
<? xml version = "1.0" encoding = "utf-8" ?>
< configuration >
< packageSources >
< clear />
< add key = "nuget.org" value = "https://api.nuget.org/v3/index.json" protocolVersion = "3" />
< add key = "github-mellowtel" value = "https://nuget.pkg.github.com/olostep/index.json" />
</ packageSources >
< packageSourceCredentials >
< github-mellowtel >
< add key = "Username" value = "mellowtel-packages" />
< add key = "ClearTextPassword" value = "YOUR_PROVIDED_TOKEN" />
</ github-mellowtel >
</ packageSourceCredentials >
</ configuration >
Replace YOUR_PROVIDED_TOKEN with the token you received from Mellowtel.
2. Install the Package
Open your terminal in the project directory and run:
dotnet add package Mellowtel.Windows
Then restore packages:
3. Add to Your Code
using MellowtelWin ;
// Initialize Mellowtel with your configuration key
var mellowtel = new Mellowtel ( "YOUR_CONFIGURATION_KEY" );
// Check if user has already opted in
if ( ! mellowtel . GetOptInStatus ())
{
// Show your consent dialog — ONLY call OptIn() if the user agrees
mellowtel . OptIn ();
}
// Start the service (throws InvalidOperationException if not opted in)
try
{
await mellowtel . StartAsync ();
}
catch ( InvalidOperationException ex )
{
Console . WriteLine ( $"Error: { ex . Message } " );
}
// Stop when your app closes
await mellowtel . StopAsync ();
Replace YOUR_CONFIGURATION_KEY with the configuration key from your Mellowtel dashboard.
Examples by Application Type
Console App
WPF App
Windows Forms
using MellowtelWin ;
class Program
{
static async Task Main ( string [] args )
{
using var mellowtel = new Mellowtel ( "YOUR_CONFIG_KEY" );
if ( ! mellowtel . GetOptInStatus ())
{
Console . WriteLine ( "User must opt in before using this service." );
return ;
}
using var cts = new CancellationTokenSource ();
Console . CancelKeyPress += ( s , e ) => { e . Cancel = true ; cts . Cancel (); };
try
{
await mellowtel . StartAsync ( cts . Token );
Console . WriteLine ( "Mellowtel running. Press Ctrl+C to stop." );
await Task . Delay ( Timeout . Infinite , cts . Token );
}
catch ( InvalidOperationException ex )
{
Console . WriteLine ( $"Cannot start: { ex . Message } " );
}
catch ( OperationCanceledException )
{
Console . WriteLine ( "Stopping..." );
}
finally
{
await mellowtel . StopAsync ();
}
}
}
Add to your MainWindow.xaml.cs: using MellowtelWin ;
using System . Windows ;
public partial class MainWindow : Window
{
private Mellowtel ? _mellowtel ;
public MainWindow ()
{
InitializeComponent ();
Loaded += Window_Loaded ;
}
private async void Window_Loaded ( object sender , RoutedEventArgs e )
{
_mellowtel = new Mellowtel ( "YOUR_CONFIG_KEY" );
_mellowtel . ConnectionStateChanged += ( s , connected ) =>
{
Dispatcher . Invoke (() =>
{
StatusTextBlock . Text = connected ? "Connected" : "Disconnected" ;
});
};
if ( _mellowtel . GetOptInStatus ())
{
try
{
await _mellowtel . StartAsync ();
}
catch ( InvalidOperationException ex )
{
Dispatcher . Invoke (() => MessageBox . Show ( $"Error: { ex . Message } " , "Error" ));
}
}
else
{
// Show your consent dialog here
}
}
protected override async void OnClosing ( CancelEventArgs e )
{
if ( _mellowtel != null )
{
await _mellowtel . StopAsync ();
_mellowtel . Dispose ();
}
base . OnClosing ( e );
}
}
Add to your MainForm.cs: using MellowtelWin ;
public partial class MainForm : Form
{
private Mellowtel ? _mellowtel ;
public MainForm ()
{
InitializeComponent ();
Load += MainForm_Load ;
FormClosing += MainForm_FormClosing ;
}
private async void MainForm_Load ( object sender , EventArgs e )
{
_mellowtel = new Mellowtel ( "YOUR_CONFIG_KEY" );
_mellowtel . ConnectionStateChanged += ( s , connected ) =>
{
if ( InvokeRequired )
Invoke (() => statusLabel . Text = connected ? "Connected" : "Disconnected" );
else
statusLabel . Text = connected ? "Connected" : "Disconnected" ;
};
if ( _mellowtel . GetOptInStatus ())
{
try
{
await _mellowtel . StartAsync ();
}
catch ( InvalidOperationException ex )
{
Invoke (() => MessageBox . Show ( $"Error: { ex . Message } " , "Error" ));
}
}
else
{
// Show your consent dialog here
}
}
private async void MainForm_FormClosing ( object sender , FormClosingEventArgs e )
{
if ( _mellowtel != null )
{
await _mellowtel . StopAsync ();
_mellowtel . Dispose ();
}
}
}
User Consent
Displaying a consent dialog is mandatory . The SDK enforces this — StartAsync() throws an InvalidOperationException if the user hasn’t opted in.
var mellowtel = new Mellowtel ( "YOUR_CONFIG_KEY" );
if ( ! mellowtel . GetOptInStatus ())
{
var userAgreed = ShowConsentDialog (); // your custom dialog
if ( userAgreed )
mellowtel . OptIn ();
else
return ; // user declined — do not start
}
try
{
await mellowtel . StartAsync ();
}
catch ( InvalidOperationException ex )
{
Console . WriteLine ( $"Error: { ex . Message } " );
}
What your consent dialog must include
Explain what Mellowtel does
Use plain language. Example: “This app uses Mellowtel to share your unused internet bandwidth. This allows you to [benefit/feature]. You can opt out at any time in settings.”
Give users a clear choice
Include distinct Accept and Decline options.
Let users change their consent in settings
// Check current status
bool isOptedIn = mellowtel . GetOptInStatus ();
// Opt out
if ( userWantsToOptOut )
{
mellowtel . OptOut ();
await mellowtel . StopAsync ();
}
// Opt back in
if ( userWantsToOptIn )
{
mellowtel . OptIn ();
await mellowtel . StartAsync ();
}
Troubleshooting
"Package not found" error
Verify nuget.config is in the correct location (the project root, next to .csproj or .sln)
Check that the token has no extra spaces
Clear the NuGet cache and retry:
dotnet nuget locals all --clear
dotnet restore
"Unauthorized" or "Authentication failed"
Verify the token in nuget.config is correct
Make sure there are no extra spaces around the token value
Estimated time to complete: 10-15 minutes.
If you need help or have feedback, contact us at info@mellowtel.com or join our Discord community .