by Patrick Stählin
In my last post I’ve shown you how you can talk to Squirro using our API. Meanwhile we’ve released sales triggers which make Squirro deliver you items that match a set of keywords, directly to your mailbox. So you never have to miss an important update again, as long as you check your mail.
Built on the same technology we’re now testing a new feature that can talk directly to your application or your CRM. This is commonly known as a ‘webhook’. Once we’ve released this feature, you don’t have to poll our API anymore but have Squirro notify you.
I did a quick demo using webscript.io, a platform, which allows you to write short scripts and let them run on their servers. This demo-page receives triggers for items containing ‘Squirro’. It receives, stores and generates a website showing all items coming in:
The Squirro item is being passed in as JSON and all we need to do in the webhook is to parse and store it. Rendering all items into a website takes up most of the code.
local template =
[[
<!doctype html>
<html>
<head>
<title>Squirro articles</title>
</head>
<body>
<h1>Articles in topic 'Squirro'</a></h1>
<ul>
{{#entries}}
<li>{{created_at}} <a href="{{{link}}}">{{title}}</a></li>
{{/entries}}
</ul>
</body>
</html>
]]
st = json.parse(storage.json or '{"entries": []}')
if request.method == 'POST' and request.body then
entry = json.parse(request.body)
table.insert(st.entries, entry)
storage.json = json.stringify(st)
return 201
end
local lustache = require 'lustache'
return lustache:render(template, st),
{['Content-Type']='text/html; charset=utf-8'}
More details on Squirro webhooks and how you can configure them will follow once we’ve made them available.