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.
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.
Comments