SMS Sentiment Analysis using Einstein

This flow allows you to use the Einstein Sentiment Analysis API in a incoming SMS.

You need a Nexmo account and set up the webhook endpoint to https://your-server/message. To learn how to set and one and receive SMS message, please read the tutorial, How to Receive SMS Messages with Node.js and Express.

To use the Einstein Sentiment Analysis API, you will first need to create a Salesforce account and obtain your private key With that key, you'll then need to create an access token Finally, insert that access token in the Einstein Access Token node

This flow requires the following libraries:

[{"id":"6704d54c.0d354c","type":"tab","label":"Einstein Sentiment Analysis","disabled":false,"info":"Accepts incoming SMS, sends to Einstein for Sentiment analysis, then sends sms back with results\n"},{"id":"8f65ade2.583d98","type":"http in","z":"6704d54c.0d354c","name":"","url":"/webhooks/inbound-message","method":"get","upload":false,"swaggerDoc":"","x":340,"y":120,"wires":[["f92dafcb.83c508","5b4d469d.372c8"]]},{"id":"e3c2743e.09745","type":"sendsms","z":"6704d54c.0d354c","creds":"920f38fd.ed198","to":"{{msg.incoming_message.msisdn}}","fr":"{{msg.incoming_message.to}}","text":"{{msg.payload.score}}","unicode":false,"x":930,"y":500,"wires":[["7027dd4d.273c9c"]]},{"id":"f92dafcb.83c508","type":"http response","z":"6704d54c.0d354c","name":"","statusCode":"200","headers":{},"x":620,"y":120,"wires":[]},{"id":"7027dd4d.273c9c","type":"debug","z":"6704d54c.0d354c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":990,"y":320,"wires":[]},{"id":"aa8a22ec.e7b38","type":"http request","z":"6704d54c.0d354c","name":"post to Einstein Sentiment API","method":"POST","ret":"obj","url":"https://api.einstein.ai/v2/language/sentiment","tls":"","x":710,"y":400,"wires":[["444a69bb.9cdc58"]]},{"id":"53f7f993.421178","type":"function","z":"6704d54c.0d354c","name":"set payload and headers","func":"msg.payload = {\"modelId\":\"CommunitySentiment\", \"document\":msg.incoming_message.text};\nmsg.headers = {};\nmsg.headers['Cache-Control'] = 'no-cache';\nmsg.headers['Content-Typey'] = 'multipart/form-data';\nmsg.headers['Authorization'] = 'Bearer ' + msg.secret;\n\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":340,"wires":[["aa8a22ec.e7b38"]]},{"id":"333a38e4.675428","type":"secret","z":"6704d54c.0d354c","name":"Einstein Access Token ","x":520,"y":280,"wires":[["53f7f993.421178"]]},{"id":"ca269c9e.b4f24","type":"comment","z":"6704d54c.0d354c","name":"Obtain your Einstein Access Token","info":"You will first need to obtain your private key\nhttps://api.einstein.ai/reset\nThen, generate a token from your private key\n\nhttps://api.einstein.ai/token\nUse that token in this node\n","x":540,"y":240,"wires":[]},{"id":"444a69bb.9cdc58","type":"function","z":"6704d54c.0d354c","name":"","func":"var positiveScore = Math.round(msg.payload.probabilities[0].probability * 100)\nvar negitiveScore = Math.round(msg.payload.probabilities[1].probability * 100)\nvar neutralScore = Math.round(msg.payload.probabilities[2].probability * 100)\n\nmsg.payload.score = \"positve:\" + positiveScore + \"% negitive: \" + negitiveScore + \"% neutral:\" +neutralScore + \"%\" \nreturn msg;","outputs":1,"noerr":0,"x":830,"y":440,"wires":[["e3c2743e.09745"]]},{"id":"5b4d469d.372c8","type":"function","z":"6704d54c.0d354c","name":"Save incoming message data to `incoming_message`","func":"msg.incoming_message = msg.payload\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":200,"wires":[["333a38e4.675428"]]},{"id":"920f38fd.ed198","type":"nexmobasic","z":""}]

Flow Info

Created 6 years, 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • debug (x1)
  • function (x3)
  • http in (x1)
  • http request (x1)
  • http response (x1)
Other

Tags

  • nexmo
  • sentiment
  • analysis
  • einstein
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option