Search code examples
asp.net-mvcwebhookswhatsapp

WhatsApp WebHook is called by someone how do I return a response from the WebHook?


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.


Solution

  • 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 );
        }
    }