Always Keep Promises : Applies to NodeJS too : AI Challenges : Claudia.js and Viber bot : Auth Token Error

The general principle of life to keep promises also applies to NodeJS to a great extent.
Whenever using third party or open libraries/sdk to integrate some platforms, never forget to use promises.
In viber bot integrations with AWS, many people use Claudia js for easy setup.
**This approach is valid for any social platform and not only Viber, but the challenge we faced was with Viber, Claudia and AWS.

Challenges/Business Use cases :
Using a business case where you need Viber to integrate with a backend service of your system. e.g. you want a user to tell his account balance on Viber using a secure service, or to accept a payment from viber etc.

Error code received :
Got the error [TypeError: Cannot read property 'auth_token' of undefined] when we made a external webservice calls via http.request in viber bot

Logical Reason and Solution
As node is asynchronous by default, so in the integrations where the security tokens (public and private key) concepts are involved, it can create problems i.e. by the time the service will yield an output, may be the auth token is lost of not present in the memory ( as node uses same memory for multiple requests )

A little more technical reason:
Request handler doesn’t return an object to make the wait for the response, so request got closed immediately. We need to include a return statement before executing the request. Request handler needs to return a Promise object to know to wait for the response. If nothing is returned from the request handler, it considers that as a synchronous handler, so terminates the call immediately.
This was the case for Viber, when we used Claudia with AWS.




If you are interested to know on exact code and how to use it, do not hesitate to contact us for any consultancy.








Comments