Posts

Send event to intercom.ie – example python code

So as mentioned in a previous post I have been doing some python software work to integrate a client’s could application with intercom.io. The intercom REST interface is nicely designed and quite straightforward to use.

Applications send events to their intercom account (with optional event data) when their users do interesting things, intercom can be configured with rules so that messages are automatically sent in response to a particular combination of events.

It is a nice idea that shows great potential, however the intercom rules engine is quite limited and probably needs quite a bit of work before it is really useful, for example, at the time of writing, it is not possible to include any of the event data as part of the decision process of a rule.

Anyway to post an event to intercom.io you do an HTTP POST to /events passing some data, including: the event name, the user’s email address a time-stamp. You can also send optional data that will be stored with the event (but which can’t bu used as part of a messaging rule).

The following code defines a function called raise_event() which can be used like this:

raise_event('project_created', email_address,
		{'project_id': id, 'project_name':name})

This raises an event named ‘project_created’ with some extra data: project id and project name.

import httplib
import json
APP_ID = 'Place your App Id here'
API_KEY = 'Place your API key here'
API_URL_STUB = 'api.intercom.io'

def raise_event(name, user_email, extra_data = None):
 
	return _api_post('events',
			 {'event_name': name,
			  'created_at':_timestamp(),
			  'user_id': user_email,
			  'email': user_email,
			  'metadata': extra_data,
					 }
	)
def _api_post(endpoint, data):
    userAndPass = b64encode(b'%s:%s' % (APP_ID, API_KEY)).decode("ascii")
    headers = {"content-type": 'application/json', 'Authorization' : 'Basic %s' %  userAndPass}
    h = httplib.HTTPSConnection(API_URL_STUB)
    url = '/%s' % endpoint
    h.request('POST', url, body=json.dumps(data), headers=headers)
    response = h.getresponse()
def _timestamp():
    now = datetime.now()
    return long(time.mktime(now.timetuple()))

Of course this is all very interesting but for a real python API wrapper you should probably checkout python-intercom here:

https://pypi.python.org/pypi/python-intercom

Integrating Intercom to cloud App keeps me out of trouble… (ARM NEON)

I have been busy over the last few days integrating Intercom into a client’s cloud app. I have integrated quite a few SaaS systems of late (and written not a few REST interfaces myself) and I am quite enjoying this integration as the data model is good and the REST interface is reasonably easy to use!

So far so good, and at least it keeps me out of trouble, the specific trouble I have in mind is to attempt to implement a visual programming front-end for the ARM NEON SIMD instructions using the very exciting noFlo Javascript library!!

The ARM NEON instructions are very powerful SIMD instructions that are very useful for optimising image processing and computer vision tasks on ARM devices. They are however quite difficult to use as each instruction has so many variants for the different input and output element types. I reckon it could be a problem well suited to visual/graph flow programming and as far as I can see the most capable people at those races are those in the noFlo team – I am getting seriously excited about their work!

Anyway back to Intercom for the moment!