Twilio - sending sms doesn't call the statusCallback URL - node.js

Twilio free account.
This is how I send the message:
const args = {
from : TWILIO_PHONE_NUMBER,
to : '+15005550006', // magic test number
body : "test",
statusCallback: 'https://postb.in/1604476976671-5019259769469' //twilioCallback.getUrl()
}
message = await this.client.messages.create(args)
Results: postbin never receives a request. nor does my own twilio callback url. Do I need to subscribe, create a messaging service, pay for a sender phone number, and use that messaging service id in the args? Does that make it work?

Magic numbers / test credentials don’t send requests. Use your production Account SID and Auth Token and a real Twilio number to send the request.
Why aren't my test credentials working?

Related

Sendgrid doesn't trigger webhook when email is sent

I'm using Sendgrid in an ASP.NET WEB API project, and I'm testing the webhook call with ngrok.
I first followed this guide: https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook
Therefore i turned on Event Webhook and tested it with their integration test.
The problem is that it works only during test, if I send an email with my software, webhook is not fired. ( I receive the email, but Ngrok doesn't record a request)
This is how i send the email:
var client = new SendGridClient(Config.sendGridApiKey);
var x = MailHelper.CreateSingleEmail( new EmailAddress(Config.mymail),
new EmailAddress(to), content, content, content);
return await client.SendEmailAsync(x).ConfigureAwait(false);
I didn't choose the event triggering the webhook from the panel.
Now it works!

Not getting response to DocuSign webhook listener url

For getting envelop status, I followed these steps
docusign developer account, under connect, I created a connect with webhook url.
In code , I have given eventNotification with webhook listener url with https:// address of my application.
I am getting response in connect logs. But I am not getting any response in my application webhook listner .why?
I have used Laravel code, with route
Route::post('webhook', [TestController::class, 'webhook']);
But I am not getting any response in function?why?
Ensure that your server (the "listener") has an https URL that is visible (callable) from the public internet. Best way to confirm this: implement a GET function at a URL such as https://your-server.com/hello. It should reply with "hello" when called. Then try entering that URL on your mobile phone.
Look at DocuSign's Connect error log to see what it says.
To assure yourself that DocuSign is sending notification messages, first use https://webhook.site to get a test webhook listener URL, and configure DocuSign to use it.
If you feel that the messages are being sent to your server but are not being received by your software, check your web server's logs. For example, if you're including documents in your notifications, the notifications will be very large and may exceed your web server's default configuration limits.
One issue which I have found, the response which is sent from Webhook to our own custom API, which will receive request from webhook does not match
For e.g.argument webhook sends json payload , so make sure you have same object which is supported by your api from docusign connect
// this is C# code
public async Task Post([FromBody] JObject envelopeData)
To test locally, you can use ngrock, which will create local server but you will be able to debug
You can try something as below. The same worked for me.
if (!Request.Body.CanSeek) { Request.EnableBuffering(); }
Request.Body.Position = 0;
var reader = new StreamReader(Request.Body, Encoding.UTF8);
var body = await reader.ReadToEndAsync().ConfigureAwait(false);

Dialogflow fullfilment code send otp using twilio in nodejs

I want to send otp to my mobile number, as part of a fulfilment on dialogflow using twilio. I have followed the instructions in https://www.twilio.com/docs/sms/tutorials/how-to-send-sms-messages-node-js link to setup twilio account and get the phone number. Have added the account sid and authtoken also in the code.But still I am not able to recieve any sms in my mobile. Any help would be appreciated. Below is the code which I have as part of OTP authentication.
app.intent('Proceed_Auth', (conv) => {
client.messages.create({
body: `You just sent an SMS from Node.js using Twilio!`,
from: '+1619XXXXXXX',
to: '+9194XXXXXXXX'
}).then(
(message) => console.log("send msg",message.sid)
);
conv.contexts.set('otp', 1);
conv.ask('I have sent an OTP to your number. Please enter the OTP');
});

Twilio using access token to send SMS

I keep reading in the doc that the access token can be used for services like Voice/Chat/Video, but I don't see anywhere mention sending SMS. Does Twilio exclude this functionality on purpose? i.e. my mobile app can acquire an access_token to send SMS
Twilio developer evangelist here.
Sending SMS messages uses the Twilio REST API and to use the REST API you always need your Account Sid. There are two ways you can authenticate to the API though.
You can either authenticate with your Account Sid and Auth Token, both found on your Twilio console. Then, using Node.js and the Twilio Node module, you would authenticate your client like this:
var client = require('twilio')(accountSid, authToken);
Alternatively, you can generate an API Key and Secret from the Twilio console or you can create an API Key and Secret using the REST API. With those credentials you can also authenticate a client, but you still need to supply the Account Sid for the resource you want to use.
var client = require('twilio')(apiKey, apiSecret, { accountSid: accountSid });
The services that use access tokens are Video, Chat, Sync and the Programmable Voice SDKs. These are all services that have SDKs and run in the client side, either on iOS, Android or in the browser. They use access tokens because they allow the developer to authenticate users with Twilio without giving away the Auth Token or API Keys.
You can send the message via twilio module with relevant information
See the example below
// Twilio Credentials
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = 'your_auth_token';
//require the Twilio module and create a REST client
var client = require('twilio')(accountSid, authToken);
client.messages.create({
to: "+15558675309",
from: "+15017250604",
body: "This is the ship that made the Kessel Run in fourteen parsecs?",
mediaUrl: "https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg",
}, function(err, message) {
console.log(message.sid);
});
You can refer the sending-messages docs here

How to verify FCM registration token on server?

I got my Firebase Cloud Messaging registration token for web push.
And I sent this to my server to save in database for later push.
But how can I verify this token is valid or fake?
I have tried this but I think this is for Auth tokens not for web push.
Someone else can send request of a random fake token to my server. I want to prevent this before save in db.
Edit: It's solved and I wrote a simple class to use FCM for web push quickly.
https://github.com/emretekince/fcm-web-push
When sending to an invalid registration token, you'll should receive 200 + error:InvalidRegistration:
Check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with Firebase Notifications. Do not truncate or add additional characters.
This is the response when you try to send a simple cURL request where the registration token is just randomly made:
curl --header "Authorization: key=$[your_server_key_here]" \
--header Content-Type:"application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"registration_ids\":[\"ABC\"]}"
Notice that I added in "ABC", in the registration_ids parameter. If ever it is a valid registration token, but is not associated to your project, you'll probably receive 200 + error:NotRegistered.
You can try sending a test message from your server to see the response without sending an actual message towards the device by using the dry_run parameter:
This parameter, when set to true, allows developers to test a request without actually sending a message.
Using Node Admin SDK
If anyone using firebase Admin SDK for node.js, there is no need to manually send the request using the server_key explicitly. Admin SDK provide sending dry_run push message to verify the fcm_token.
function verifyFCMToken (fcmToken) => {
return admin.messaging().send({
token: fcmToken
}, true)
}
Use this method like following
verifyFCMToken("YOUR_FCM_TOKEN_HERE")
.then(result => {
// YOUR TOKEN IS VALID
})
.catch(err => {
// YOUR TOKEN IS INVALID
})
Using Java Admin SDK
You can use following function
public Boolean isValidFCMToken(String fcmToken) {
Message message = Message.builder().setToken(fcmToken).build();
try {
FirebaseMessaging.getInstance().send(message);
return true;
} catch (FirebaseMessagingException fme) {
logger.error("Firebase token verification exception", fme);
return false;
}
}
One way is to send a message with the dry_run option = true, as is described by AL. in the other answer.
Another way is to use the InstanceId server API:
https://developers.google.com/instance-id/reference/server
According to the docs, you can use validate_only for testing the request without actually delivering the message.
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send
You can refer to doc for using HTTP v1 of the firebase endpoint URL
After that, you could use this request body with "validate_only": true for testing the request without actually delivering the message.
{
"validate_only": true,
"message": {
"token": "your fcm token"
}
}

Resources