How to integrate twilio sms verification into my Node.js application - node.js

As I am integrating Twilio into my website. It is first of all not working. My code is this
and app crashes. my userController where I am implementing the code is here
I am not getting what I want. This is what I am getting on my front UI

You see the error because you didn't supply a to parameter. This probably happens when the first function argument of sendSms() is null or undefined.
You call sendSms(User.newphone) which is probably the mistake as you call the property of what I assume is a class but instead you should try sendSms(user.newphone) or sendSms(newphone).
Tip: Don't use the same variable name to avoid this in the future.

Related

WebhookClient doesn't work when i call api

I'm working on an app for Google Home with DialogFlowV2 but I've got a problem.
I'm using Google Cloud Functions, I've defined 3 functions, welcome, fallback and getTVShow.
The third one is the interesting one, i'm getting data from an API and send it with the add method of webhookClient.
I got this error when I call it :
Error: No responses defined for undefined
at V2Agent.sendResponse_ (/user_code/node_modules/dialogflow-fulfillment/v2-agent.js:140:13)
at WebhookClient.send_ (/user_code/node_modules/dialogflow-fulfillment/dialogflow-fulfillment.js:225:19)
at promise.then (/user_code/node_modules/dialogflow-fulfillment/dialogflow-fulfillment.js:285:38)
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
I've looked into the source code and this is corresponding to the request source which is undefined after getting the data from the source in originalDetectIntentRequest from the request body.
So, i've done a console.log on the request.body.originalDetectIntentRequest and the result is :
{ payload: {} }
Therefore, it's normal to have an error but i don't want it.
Can someone help me, please ?
UPDATE
I’ve find out it only happens when i use the “playground” from DialogFlow. It's the "Try it now" input at https://console.dialogflow.com/ right side.
I've post an issue about this on the GitHub repo.
UPDATE 2
It was all about a forgotten return. When using async requests, we need to return the promise.

Stripe returning token but can access it

I am getting a stripe token back from my stripe.tokens.create now I can assign it to a variable inside it but I need to call that variable outside the callback. I was thinking global variable but then thought it might not work. I know the code examples I have found use req.body.stripeToken but my req.body comes back with a blank object {}. I can not find any guides on this for Node.js only stuff like Ruby and PHP.

Cannot display an overview of this response error in nexmo

i tried to run the code present in the below link
https://github.com/linroex/Nexmo-PHP-Library/blob/master/NexmoMessage.php
but i am getting cannot display overview of this response.warning Invalid argument supplied for foreach() in NexmoMessage.php on line 228.
or else please suggest some api to be used to send sms to phone using php which could be implemented easily
Check out https://docs.nexmo.com/tools/libraries for a list of libraries Nexmo recommends. Personally I'm a fan of https://github.com/fillup/nexmo since I wrote it, but I'm sure https://github.com/appleboy/CodeIgniter-Nexmo-Message is great too. If you try the fillup/nexmo library and have any issues let me know, will be glad to help.

How to send POST variables with Nipple on NodeJS

I am trying to use nipple to post to an url within my nodejs application, which itself is running on hapi.js
The documentation essentially doesn't seem to spell it out.
(https://www.npmjs.com/package/nipple)
I tried passing it as payload inside options but that, while not returning an error, returns a 400. Can someone provide a correct example doing a post using nipple?
Essentially, I have two variables that I need to send - let's call the var1 and var2.
Thanks!
That link says that the project has been renamed to wreck. On wreck's github, several of the tests are for a post requests, including this one:
https://github.com/hapijs/wreck/blob/master/test/index.js#L68
If you are still scratching your head, you could also try using curl or postman to sanity check your URL, regardless of any nipple/wreck errors. If that also gives you a 400, nipple/wreck may not be the culprit.

Manage errors and translations in nodejs

My nodejs application uses a basic REST communication style to allow an HTML web ui to pass commands.
For instance:
http://address/api/config/cmd1
http://address/api/config/cmd2
http://address/api/network/cmd3
...
In return, my web ui gets a JSON result of the form:
{
"success": true
}
or
{
"success": false,
"errorMsg": "Wrong parameter blabla"
}
My problem is, I now need to translate error messages on client-side (in many languages), and the english "errorMsg" is too variadic and too long to be a translation key.
So I need something like an "errorCode" (an integer, probably) and I'm searching for a strategy into my nodejs application to manage error codes. I don't really know what is usually done for that, considering I usually use throw new Error("message") to return the message directly to the web ui.
I don't know if it's better to make a list of uniq error codes for all my REST API of a contextual error list for every subset of this API.
UPDATE: finally, I opted for a string error id. For instance, "wrong argument for this command" becomes "WrongArgument" and will be used to identify the error on GUI side and thus, perform the localization process. And finally, I don't need to make the error id uniq.
Using a custom Error class in the back-end with error identifier will allow the front-end to directly use its translation module, without modifications.
From your Server, one can process the standard error by creating a custom class, throw the class, catch it in your controller and send to the front-end the response with correct http status and error id.
The reasons are:
1 - Front-end code maintanability.
2 - Keeping errors systems data on back-end logs because they might be sensitive. It should not be return to the client side.
I agree with naming identifier code instead of using a code number. This because it s hard to pre-define a range for each error type (SQL, API, Authentication...). And it s harder when the error may be found in different service.
Scope: In the front-end service, i define a scope when calling the server, so that if there is need for a global error to be more specific, it is there. The scope is just a string with the name of the page where the ressources is used, also found in JSON lang files.
If 'ld like to check this code out and give comments, it will be great:
'https://codepen.io/Aymer-El/pen/OJoRVgZ'
Also leaving place for a debug message in the response may help front-end devs. Tho, this is optional.

Resources