How to send whatsapp message using Twilio asynchronously

Arturo Lozano

Hi,

I want to be able to send Whatsapp messages using Twilio, but I need it to be asynchronously. Here is my code:

public async void EnvioWhatsapp(string TelefonoCelular)
{
    const string accountSid = "mySid";
    const string authToken = "myToken";

    TwilioClient.Init(accountSid, authToken);

    var message = MessageResource.Create
        (
                body: "Hola mundo!",
                from: new Twilio.Types.PhoneNumber("whatsapp:+myNumber"),
                to: new Twilio.Types.PhoneNumber("whatsapp:+clientNumber")
        );
}

In my code EnvioWhatsapp is underlined in green with the message:

"This async method lacks await operators and will run synchronously. Consider using the await operator to await non-blocking API calls..."

I have tried inserting await in multiple areas of the method but nothing works so far, and yes I have been looking at the Twilio api docs, but I cannot find a way to make the call asynchronously.

Thank you, and sorry for the Spanish nomenclature, I know it makes it a little harder to read the code.

Stefan

According to the docs you should use CreateAsync.

You can either return it as Task, or await it. In any case try to avoid the async void signature. See: https://docs.microsoft.com/en-us/archive/msdn-magazine/2013/march/async-await-best-practices-in-asynchronous-programming#avoid-async-void

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to send whatsApp message to any number by using twilio using c#

Send WhatsApp Notification using Pre-approved Template Message on Twilio

how to send a message and wait for a reply in python, twilio in whatsapp

How to send a whatsapp message through twilio via zapier webhook

Twilio Laravel Send Whatsapp Message not in same channel

how to send message to whatsapp number programmatically using C#

Android: How to send message programmatically by using WhatsApp, WeChat?

How to send new line whatsapp message using PHP/JavaScript?

Send Message using a WebRequest and Twilio

How to send custom notifications using twilio whatsapp without registering receiver's number?

how to send locally stored media files using twilio over whatsapp .. node js express

Is there anyway to send WhatsApp message using node js?

Send message and files to whatsapp using laravel

How to send a text message with Whatsapp Cloud API

How to send a message in whatsApp by clicking on thebutton

How to send whatsapp message in whatsapp-web.js

How to Send message to a WhatsApp group without opening WhatsApp?

Send whatsapp massage from Twilio using my number

Using Sidekiq and Twilio to send text message

Twilio: Unable to send Message using Test Credentials

How to read whatsapp message (phone number + body content) with nodejs and twilio?

Twilio SMS (Whatsapp): Send Location

How can I send messages to WhatsApp using WhatsApp Cloud API without registering the recipient number prior to sending message?

Android : How to send app invite message using whatsapp,facebook,gmail,etc from my app

How can I Send message to WhatsApp Group and Sync contacts using WhatsAPI?

how to send whatsapp message to Paticular Contact without Click on send button

How to send hero card from bot framework to WhatsApp by Twilio WhatsApp API

How to send message from WhatsApp in PHP with WhatsAPI Official?

Send message via whatsapp programmatically