如何通过Twilio发送WhatsApp消息,并通过手机管理回复?

huangapple go评论54阅读模式
英文:

How to send whatsapp messages via twilio and manage the replies via the mobile phone?

问题

I would like to send a Whatsapp message via Twilio and be able to manage the response via the WhatsApp mobile app. So, I want the same account to be accessed via the API and the mobile app. Twilio gives me the error message below:

"This number is registered to an existing WhatsApp account. To use
this number, disconnect it from the existing account. Then, return to
this page and re-enter the number. Note: It may take up to 3 minutes
for the number to become available."

How can I accomplish this?

I use this code to send WhatsApp messages via Twilio:

TwilioClient.Init(_Configs.Twilio.SID, _Configs.Twilio.Token);

var message = MessageResource.Create(
    body: whatsapp.Message,
    from: new Twilio.Types.PhoneNumber("whatsapp:" + _Configs.Twilio.FromNumberWhatsapp),
    to: new Twilio.Types.PhoneNumber("whatsapp:+27" + whatsapp.CellNumber.Trim().Substring(1))
);

Please recommend another service provider if it can't be done via Twilio.

英文:

I would like to send a Whatsapp message via Twilio and be able manage the response via whatsapp mobile app. So i want the same account to be accessed via the api and the mobile App. Twilio gives me the error message below :

> "This number is registered to an existing WhatsApp account. To use
> this number, disconnect it from the existing account. Then, return to
> this page and re-enter the number. Note: It may take up to 3 minutes
> for the number to become available."

How can I accomplish this?

I use this code to send whatsapp message via Twilio :

  TwilioClient.Init(_Configs.Twilio.SID, _Configs.Twilio.Token);

                var message = MessageResource.Create(
                    body: whatsapp.Message,
                    from: new Twilio.Types.PhoneNumber("whatsapp:" + _Configs.Twilio.FromNumberWhatsapp), 
                    to: new Twilio.Types.PhoneNumber("whatsapp:+27" + whatsapp.CellNumber.Trim().Substring(1))
                );

Please recommend another service provider if it cant be done via Twilio.

答案1

得分: 1

以下是翻译好的部分:

你展示的代码将发送一条文本消息。如果有人回复该消息,您将从Twilio收到一个Webhook请求。您需要设置一个Web应用程序来处理该请求。

您是否在使用.NET?
如果是的话,您可以:

  1. 创建一个带有ASP.NET的MVC项目
  2. 安装Twilio.AspNet.Mvc
  3. 创建一个控制器,例如SmsController.cs
  4. 粘贴以下代码:
using Twilio.AspNet.Common;
using Twilio.AspNet.Mvc;
using Twilio.TwiML;

namespace WebApplication1.Controllers {
  public class SmsController: TwilioController {
    public TwiMLResult Index(SmsRequest incomingMessage) {
      var messagingResponse = new MessagingResponse();
      messagingResponse.Message("The copy cat says: " +
        incomingMessage.Body);

      return TwiML(messagingResponse);
    }

  }
}
  1. 运行应用程序
  2. 托管您的应用程序,您可以使用ngrok来通过从互联网到本地主机的隧道来测试它。
  3. 复制公共URL并将其添加到Twilio控制台,并在消息到来时进行配置,它应该命中此URL。

如果您需要更多详细信息,请查看如何使用ASP.NET MVC接收和回复入站短信消息的文档

英文:

The code you showed will send out a text message. If someone replies to that message, you'll receive a webhook request from Twilio. You'll need to set up a web application to handle that request.

Are you using .NET?
If so, you can:

  1. Create an MVC project with ASP.NET
  2. Install the Twilio.AspNet.Mvc package
  3. Create a controller, i.e. SmsController.cs
  4. Paste in the following code:
using Twilio.AspNet.Common;
using Twilio.AspNet.Mvc;
using Twilio.TwiML;

namespace WebApplication1.Controllers {
  public class SmsController: TwilioController {
    public TwiMLResult Index(SmsRequest incomingMessage) {
      var messagingResponse = new MessagingResponse();
      messagingResponse.Message("The copy cat says: " +
        incomingMessage.Body);

      return TwiML(messagingResponse);
    }

  }
}
  1. Run the application
  2. Host your app, you can use ngrok to test it out by creating a tunnel from the Internet to your localhost.
  3. Copy the public URL and add it to your Twilio Console, and configure it when a Message comes in, it should hit this URL.

If you want more details, check out the documentation on how to Receive and Reply to Inbound SMS Messages with ASP.NET MVC.

答案2

得分: 0

这个错误消息是正确的。你不能在手机上使用WA号码,也不能在Twilio(或任何其他通信平台)上使用。如果你想要使用人工编写和自动化消息的混合,你可以构建一个应用程序,用户可以编写消息,然后通过API发送。

英文:

This error message is correct. You cannot use a WA number on a mobile phone and on Twilio (or any other communications platform). If you want to use a mix of human-written and automated messages, you can build an application where a user can write the message that is then sent via the API.

huangapple
  • 本文由 发表于 2023年5月15日 02:56:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76249207.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定