Ivan Climov

Ivan Climov

  • 961
  • 685
  • 21.3k

How to make a “webhook”?

Jul 2 2019 2:26 AM
I need the "WinForm" application for correspondence in viber.
"Webhook" is planned to receive data (events) from viber, then the data will be used in the application "WinForm".
 
I did:
  1. created the project "ASP.NET Web Application (.NET Framework)";
  2. chose a template - "Empty" + "MVC" + "API";
  3. added controller "Controller MVC 5 - empty". Controller name "HookController";
  4. I run the application "Postman";
  5. "Postman". I set the request "POST";
  6. "Postman". I set the link http://localhost:44836/Hook;
  7. "Postman". Click "SEND";
  8. The result, see the picture "- = RESULT = -";
If I understand the theory correctly, then after performing the "Postman" action. I click "SEND", the ViberProcess (HttpContext context) method should be executed in the HookController.cscontroller and the code should stop at the breakpoint.
 
This is not happening.
 
Documentation Viber REST API - link
 
Question.
 
How to make a Webhook?

Code HookController.cs
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.IO;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Mvc;  
  7.       
  8. //  
  9. using System.Runtime.Remoting.Contexts;  
  10.       
  11. namespace WebAppl1.Controllers  
  12. {  
  13.     public class HookController : Controller  
  14.     {  
  15.         // GET: Hook  
  16.         //public ActionResult Index()  
  17.         //{  
  18.         //    return View();  
  19.         //}  
  20.       
  21.          [HttpPost]  
  22.         // [ScriptMethod(ResponseFormat = ResponseFormat.Json)]  
  23.         public void ViberProcess(HttpContext context)  
  24.         {  
  25.             try  
  26.             {  
  27.                 Stream s = context.Request.InputStream;  
  28.                 // Stream s = Context.Request.InputStream;  
  29.                 // or  Stream s  = HttpContext.Current.Request.InputStream;  
  30.                 s.Position = 0;  
  31.                 StreamReader reader = new StreamReader(s);  
  32.                 string jsonText = reader.ReadToEnd();  
  33.       
  34.                 // Other code that converts json text to classes  
  35.             }  
  36.             catch (Exception e)  
  37.             {  
  38.                 // .....  
  39.             }  
  40.         }  
  41.     }  
  42. }
 
 
7. "Postman". Click "SEND";
 
 
8. The result, see the picture "- = RESULT = -"; 
 
 
 
Server error in application '/'. Could not find this resource. Description: HTTP 404. The resource (or one of its dependencies) may have been deleted, received a different name, or may be temporarily unavailable. Review the following URL and verify that it is correct. Requested URL: / Hook Version Information: Microsoft .NET Framework Version 4.0.30319; ASP.NET version: 4.7.3062.0

Answers (4)