英文:
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?
如果是的话,您可以:
- 创建一个带有ASP.NET的MVC项目
- 安装
Twilio.AspNet.Mvc
包 - 创建一个控制器,例如
SmsController.cs
- 粘贴以下代码:
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);
}
}
}
- 运行应用程序
- 托管您的应用程序,您可以使用ngrok来通过从互联网到本地主机的隧道来测试它。
- 复制公共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:
- Create an MVC project with ASP.NET
- Install the
Twilio.AspNet.Mvc
package - Create a controller, i.e.
SmsController.cs
- 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);
}
}
}
- Run the application
- Host your app, you can use ngrok to test it out by creating a tunnel from the Internet to your localhost.
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论