Send a WhatsApp message with C# in 30 Seconds
Time to read: 2 minutes
We've already shown you how to add SMS messages to your application but now, with the new Twilio API for WhatsApp, you can send a WhatsApp message in much the same way.
And quickly.
Here's a thirty-second video showing you just how quickly.
And just to make this super easy to get started, below is all the code and a link to the completed project on GitHub.
If you would like to see a full integration of Twilio APIs in a .NET Core application then checkout this free 5-part video series I created. It's separate from this blog post tutorial but will give you a full run down of many APIs at once.
What you'll need:
- A Twilio account (sign up for a free Twilio account here)
- The .NET Core 2.1 SDK and runtime
- The WhatsApp Sandbox Channel installed in your account (go through this process to activate the sandbox)
After you have created your new .NET Console application, add the Twilio NuGet package to the solution. If you are unsure how to do this, check out this post.
Open the Program.cs
file and add in the Twilio using statement. Initialise the Twilio REST client using your Account SID and Auth Token, which you will find in the Twilio console.
I have added my Account SID and Auth Token as Environment Variables but you could also add them via App Settings and User Secrets.
Let’s restore the NuGet packages to ensure we have them all downloaded, then build and run the project.
In no time at all, you'll hear a beep and your WhatsApp message will have arrived!
What next?
You've quickly built a simple application enabling you to send a WhatsApp message, now you can progress to integrating it into your existing applications.
Check out the WhatsApp quickstarts, Twilio REST API documentation and the C#/.NET helper libraries for more ideas and useful tips.
Let me know what you come up with and feel free to get in touch with any questions. I can’t wait to see what you build!
- Email: lporter@twilio.com
- Twitter: @LaylaCodesIt
- GitHub: layla-p
Twilio.org helps social impact organizations expand their reach and scale their missions. Build your first application with Twilio and start engaging your audience at no cost with product credits from the Impact Access Program. Learn more about eligibility and how to start your benefits today.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.