The Spark Army Knife is made to be your personal bot, or your agent, if you like, and it does things on your behalf (with your credentials), like inviting people to a room through a link, tracking messages from important people, or pin important messages. To do this, it needs as much information as possible about what is going on, but the Spark APIs have been limited in the fact that webhooks had to be created for each of the rooms you want messages from, and there were no webhooks to inform you about new rooms you have been added to. This has now been fixed with the new firehose webhook!
The API limitations made the code of the Spark Army Knife unnecessary complex. It had to do a poll on all your rooms to see if any new rooms had been added and then add a webhook for every single room, and manage these. I have now updated the code to use the new firehose webhooks and made a number of simplifications. For example, the new version does not store rooms in the database anymore, just message ids from VIPs you track. Instead it will retrieve the room title when it prints out the messages when you do a /get <all/nickname>.
I have also added a new command /cleanwebhooks, which will delete ALL webhooks for your account, also for other bots or webhooks created using the API (so be careful!). If you try out various apps and want to be sure that nobody receives your messages anymore (except the Spark Army Knife), use the /cleanwebhooks command. Note that the integration webhooks will not be affected.
Another thing that has annoyed me in Spark is that you don’t really get notified when you are added to a room. I have fixed this by adding a new message sent to the Army Control room, so if you have notifications turned on in this room, you will now get notifications on new rooms you are added to!
Enough talk, to the code. I have made it easier to just get the Spark Army Knife code, including the right version of the ActingWeb library. A new code repository now mirrors the code from my Spark Army Knife app found at https://spark-army-knife.greger.io/. The version described here can be downloaded in a zip file. As you may notice, I have also now used my own domain to make it very explicit that the version of the spark-army-knife you are using is controlled by me.
How do you make your own fully operational Spark app based on this code? The procedure is just like described in a previous blog post, but using the code in the zip file above. You still need to edit app.yaml as described, and then your app name and URL, as well as Spark client id and secret must be edited in the actingweb/config.py. That’s it!
If you want to have a look at the code to see what’s changed, the structure is the same as documented in the initial Spark Army Knife post. The code piece to register a firehose is really simple using the registerWebHook() function from ciscospark.py.
hook = spark.registerWebHook(name='Firehose', target=Config.root + myself.id + '/callbacks/firehose', resource='all', event='all')
This will fire off a webhook POST message to Spark with resource set to ‘all’ and event set to ‘all’. That’s it!
To add new Spark functionality (or change) to your new Spark agent, you just need to edit two files: on_aw/on_aw_callbacks.py file to handle new commands, as well as the ciscospark/ciscospark.py file to do Spark API calls.
- config.py cleaned up a bit
- Changed /get <all/nickname> into retrieving the room title from Spark when listing messages
- Added new getRoom(id) method to ciscospark.py
- Changed the /makepublic and /makeprivate commands to be the sole users of the Room db
- Got rid of the the getRooms() (get all rooms from spark)
- Changed the addUUID2room function to store necessary info about a room (as it will not be stored earlier)
- Changed the functionality in on_aw_oauth.py to only create one firehose webhook
- Got rid of roomAlreadyHooked(), hookAllRooms(), unhookAllRooms() functions
- Changed on_aw_delete.py to clean up firehose, not one webhook per room
- Added a new /cleanwebhooks command to on_aw_callbacks.py
- Added new cleanAllWebhooks() and getAllWebHooks() functions
- Added new functionality posting a new message to the Army Knife Control room when the user is added to a new room
- (Jul16) Added support and use of markdown in posted messages
- Added markdown bool as optional argument to postMessage (to use new markdown functionality in Spark)
- Changed posted messages in commands to use markdown (on_aw_callbacks.py)
- (Jul16) Added a new feature to post a notification to the Army Knife Control room when you are mentioned
- New template and error handling if user tries to get added to a room and already is a member (/makepublic)
- Fix in on_aw_oauth_success where token can optionally supplied (first time oauth was done the token has not been flushed to db)
- Fix in on_aw_oauth_success where login attempt with wrong Spark user did not clear the cookie_redirect variable
- Removed sipaddress from stored rooms as this is no longer supported in spark
- From actingweb library update: fixed issue with wrong Content-Type header for GET and DELETE messages without json body
- Cleaned up “hidden” code to list rooms from /www path of actor
- (Jul16) Added a new test of the actor’s oauthId (spark id) for matching to avoid one actor answering a message from another user (security issue closed).