英文:
WhatsApp WebHook is called by someone how do I return a response from the WebHook?
问题
我对WhatsApp相当新,所以这可能是一个非常简单的问题。
当我的Webhook被用户调用并带有一个快速回复时,比方说一个"OK"的消息,我想要返回一个简单的文本消息,比如"很好"。应该如何实现?我需要配置一个聊天机器人吗?发送一个新的文本消息吗?
当前的控制器是asp.net MVC 5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Hook(Root data)
{
Entry entry = data.entry.First();
Change change = entry.changes.First();
List<Message> messages = change.value.messages;
string body = messages.First().text.body;
// 在这里返回一个真实的响应,例如:"祝你有美好的一天!"
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
我希望能够返回一个真实的响应,例如:"祝你有美好的一天!"。
感谢您的建议和见解。
英文:
I am fairly new to WhatsApp so this may be a very simple problem.
When my webhook gets called by a user with a quick reply, let's just say a "OK" message and I want to return a simple text message such as "Great". How is that done? Do I need to configure a ChatBot? Send a new text message?
The current controller, asp.net MVC 5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Hook( Root data )
{
Entry entry = data.entry.First();
Change change = entry.changes.First();
List<Message> messages = change.value.messages;
string body = messages.First().text.body;
return new HttpStatusCodeResult( HttpStatusCode.OK );
}
I would like to be able to return a real response, "Have a great day!", for example.
Suggestions and insight are appreciated.
答案1
得分: 0
你可以使用以下代码添加字符串:
return Content("Great", "text/plain");
更新
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Hook(Root data)
{
try
{
Entry entry = data.entry.First();
Change change = entry.changes.First();
List<Message> messages = change.value.messages;
string body = messages.First().text.body;
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
catch (Exception ex)
{
// 记录异常错误
return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
}
}
英文:
You can add the string with the following code:
return Content("Great", "text/plain");
Update
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Hook( Root data )
{
try
{
Entry entry = data.entry.First();
Change change = entry.changes.First();
List<Message> messages = change.value.messages;
string body = messages.First().text.body;
return new HttpStatusCodeResult( HttpStatusCode.Ok);
}
catch(Exception ex)
{
// Log Exception Error
return new HttpStatusCodeResult( HttpStatusCode.InternalServerError );
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论