Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To use .Net Maui to send a message on WhatsApp, you can follow these steps:

  1. Add the Xamarin.Essentials NuGet package to your .Net Maui project.

  2. Use the following code to open WhatsApp and send the message:

using Xamarin.Essentials;

var message = "Hello, world!";
var recipient = "+123456789"; // the phone number of the recipient in the international format

await Launcher.OpenAsync($"whatsapp://send?phone={recipient}&text={message}");

Replace Hello, world! with the message you want to send and +123456789 with the phone number of the recipient.

  1. Ensure that the recipient has WhatsApp installed on their phone and that their phone number is correct.

  2. Run your .Net Maui app and click the button or perform the action that triggers the code above to send the message on WhatsApp.

Note that sending messages on WhatsApp via code requires the WhatsApp app to be installed on the device. If the app is not install, an exception will be thrown.