- Create a cognitive services resource, grab the key
- Create a Function App via functions.azure.com (or use an existing one)
- Create a node Generic WebHook function (I named mine "sentiment")
- Copy index.js into the function
- Install request and node-uuid (Function App Settings -> Advanced Settings -> Tools -> Console;
cd ./sentiment
;npm install request node-uuid
) - Add the "COG_URL" and "COG_KEY" App Settings
- Test via the test box below the fold - Input data:
{ text: "Azure Functions is freaking AMAZING!!!" }
- Create a Logic App
- You can try using the LogicApp.json in the code view, but you need to set up the Connectors and change the ARM resource tag to your Function App. Alternatively, you can recreate it manually, described below.
- Add Twitter connector, based on search, I did mine on "azure functions"
- Add new step, click on the carrot on the top of the card and choose "Functions". Find your Function App and "Sentiment" function
- Input should be
{"text": "
"}
- Add slack output (or email, or whatever)
The only odd thing is that if you return a JSON object (as I did in my sample code, you can't have logic apps "discover" it in the designer, so you need to do it manually. You can see in line 23, I add ['score']
after @body('sentiment')
. We'll be adding swagger support sometime later on to make that smoother.
- Open the portal
- Show cognitive services
- Show the Logic App flow
- Show the Function Code
- Show the output in Slack