team-telnyx / telnyx-node

Node SDK for the Telnyx API
https://developers.telnyx.com/docs/api/v2/overview
MIT License
51 stars 20 forks source link

Receiving Messages #9

Closed marc8lange closed 4 years ago

marc8lange commented 5 years ago

Hello,

We are struggling with receiving messages using node (v10) and the library. We get error "Signature is invalid and does not match the payload" here is the code example which we are using:

const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); const telnyx = require('telnyx')('API key'); exports.receiveSMSTelnyx = functions.https.onRequest((request, response) => { var event; try { // Try adding the Event as request.event event = telnyx.webhooks.constructEvent( request.rawBody, request.headers['telnyx-signature'], request.headers['telnyx-timestamp'], 'public key' ); } catch (e) { // If constructEvent throws an error, respond with the message and return. console.log('Error', e.message);

    return response.status(400).send('Webhook Error:' + e.message);
  }
   console.log('Success', event.id);
   return console.log('Success', event.id);

});

lucasassisrosa commented 5 years ago

hello @marc8lange,

Could you provide info on node and npm versions along with the package version you're using?

lucasassisrosa commented 5 years ago

@marc8lange a fix is coming out in v1.2.2. Please check it out when it's released and this flow should be fixed

lucasassisrosa commented 5 years ago

@marc8lange v1.2.2 released