Wednesday, 13 July 2016

Arrivals just arrived to @london_tube_bot



After some more fiddling with @london_tube_bot I figured a feature I really need for myself: as I often run to the timetable, I need a way of quickly checking when is my next train due at my station. Naturally, I decided that I had to add it to my bot. And boy, was it an interesting journey ...

The problem as I see it is that TfL's API inherits their data model, which, in its turn, inherits their complex relationship with different train operators. Did you know, for example, that Kew Gardens is not a station, but, in fact, two stations located exactly at the same place - Kew Gardens London Underground station, and Kew Gardens National Rail station? And yes, if you want to fetch arrivals from this station, you will have to do it separately from these two. More interesting: from TfL's perspective there's no Tube on this station - just Overground and National Rail. That probably makes District Line a commuter train somewhere half the way.

Anyway, here it is, enjoy!

Sunday, 10 July 2016

Telegram bots all the way

So it suddenly became rather cool writing various bots, and I was like, I want to build one as well. There was no good reason for it, and distinct lack of good ideas, but then I got an email from TfL, reminding that once upon a time I signed up for their API key ... bingo! That did sound like a plan.
And this is how @london_tube_bot was born. Right now it is fairly stupid, and can either:
  • Give full status breakdown for all lines (/status/ command)
  • Give an update on specific line (/line <line-name> command)
  • Send a not very helpful help message (/help)


Not really sure if I'm planning to develop it any further, as this was a very simple proof of concept ("because I can") -- but if you are interested, I can publish the code to GitHub at some point.
From the technical standpoint there were a few interesting observations:
  • Telegram documentation is shit. Most of what I learned I did by reverse-engineering the messages they send.
  • OTOH, Telegram API is awesomely simple - I used Advanced Rest Client to do most of my testing to play with it (cUrl would work as well, but former is far more user-friendly).
  • Building a bot on AppEngine is surprisingly easy once you get a gist of it -- I think this is the best platform for doing this at this point, as you get fully-working WebHooks for free.
  • jsonschema2pojo.org totally rocks - I used it to build Java wrappers (yes, I used Java - just because I didn't feel like learning yet another language at this point) for JSON messages, without even having any dedicated JSON schema document. Works like a charm and requires only minimal manual fixing after classes are generated.
All things considered, I think this were half a day well spent - should I add support for Google Allo once it's out? :)