"Webhook" is planned to receive data (events) from viber, then the data will be used in the application "WinForm".
I did:
- created the project "ASP.NET Web Application (.NET Framework)";
- chose a template - "Empty" + "MVC" + "API";
- added controller "Controller MVC 5 - empty". Controller name "HookController";
- I run the application "Postman";
- "Postman". I set the request "POST";
- "Postman". I set the link http://localhost:44836/Hook;
- "Postman". Click "SEND";
- 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
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- //
- using System.Runtime.Remoting.Contexts;
- namespace WebAppl1.Controllers
- {
- public class HookController : Controller
- {
- // GET: Hook
- //public ActionResult Index()
- //{
- // return View();
- //}
- [HttpPost]
- // [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
- public void ViberProcess(HttpContext context)
- {
- try
- {
- Stream s = context.Request.InputStream;
- // Stream s = Context.Request.InputStream;
- // or Stream s = HttpContext.Current.Request.InputStream;
- s.Position = 0;
- StreamReader reader = new StreamReader(s);
- string jsonText = reader.ReadToEnd();
- // Other code that converts json text to classes
- }
- catch (Exception e)
- {
- // .....
- }
- }
- }
- }
7. "Postman". Click "SEND";
8. The result, see the picture "- = RESULT = -";
Guest UserPosted Jul 2, 2019, 4:50 AM
Ivan ClimovPosted Jul 2, 2019, 2:54 AM
@pritaeas
Madan ShekarPosted Jul 2, 2019, 2:44 AM
Guest UserPosted Jul 2, 2019, 2:37 AM