 Our next speaker will be Tim, who will be talking to us, not about software defined networking and about push notifications. Okay, thank you. This is a somewhat rushed talk. As most of you will have been aware, I gave a quick lightning talk yesterday where I mentioned that I told Tommy that I was going to submit a proposal and never got around to it. And then last night at the dinner, he mentioned that one of the speakers had cancelled and could I fill a slot? And I'm like, sure, I can waffle for half an hour. So I'm the emergency waffler. So I've got this week's start-up with my wife and another co-founder. And it's all about event management or event communications. We're the idea of being able to organize an event and communicate the changes in one step. So it's cool to know about when and where, and where you think it's kind of cool. And it's been incredibly slow to get going because I work full-time. And my wife works full-time, and the other co-founder works full-time. So in the end it comes down to end of the day, kids are in bed, done the dishes, tidy it up, it's 9pm, you're kind of knackered. And it's like, well, I could sit down and watch an episode of something on TV or I could go into the office and work on my cool project. Sometimes it's a bit of a challenge to get that enthusiasm. So it's slow coming and the website, if you went and had a look at it now you'll see something that says we're in a closed beta, but we're not because I've not fixed the homepage yet. And it's a default Twitter bootstrap type homepage that looks like a developer wrote it because one did. So it's not a fancy website, but anyway. So what we've got is we have phone apps that we've developed and ideally we wanted to be able to have changes to events be sent to the people that need to know about those events. So part of the problem that we're trying to solve is as parents we have three kids. Three kids were at three different schools each doing different after-school activities. And traditionally the communication method of the school to the parents was through the kids and sometimes a piece of paper. Sometimes it was the website for the school and you would go to the sports draw page and then it would have different links for all of the different sports and sometimes they would take you to a PDF on Scribe. Sometimes it would be a link to a Word document or something else and you would have to go hunting. The worst ones were a link to a local sports website which you then had to go to say a Targo netball and then try and work out what grades my daughter in. I have no idea. And you had to figure that out before you could find out where our game was. And then the other thing is I say, what's her team name? The school chose that. I had no idea. So what we're trying to do is solve the problem of if the school puts them in a team, I know who my daughter is and I know my email address. So the school has got my daughter and they link my email address to her and so that can create a connection between me as a user of the site and the school who's managing my daughter and teams. They put her into a team and they'll create a game. So as soon as they've put my daughter in a game for the team I should see it on my little app to say Maya has a game of netball at 3.30 on Thursday. So that was what we wanted to see and there was nothing out there that we could see that would solve this problem and my wife who's full of ideas said, we could write one. When she said we, she meant you. But my wife is great, ideas person. She's got so many ideas for startups and this is the first one that I felt I could actually do. A lot of the other ones she came up with some central login thing. We were effectively like last pass. We could do all the password management and I'm like I don't know how to do that. And so that one didn't happen. The whole pile of other ones that didn't happen. So this was the first one that did. So we have apps which is another whole talk. So we've got Android apps and we've got iPhone apps and we wanted to send push notifications because the big thing is things change and particularly in Dunedin where the weather is not always as awesome as it is right now in winter time for example football the DCC will go out to the grounds early in the morning and go ooh, this one's a bit soggy. Let's move the game to another location. And at short notice they will move all of the games on that field to another place for that day. Now if you're a parent of someone that plays football and you're expecting to go to this location and they've changed it to somewhere else it's awkward. And so what we wanted was a system that when that change happens someone's changed the location of the game that you would get notified. Something in your pocket would go bing and you could look at it go oh, the games moved to another location. Awesome. I am now going to go to the right place. So this is what we wanted and so I had to get myself into the idea of push notifications. So Amazon SNS is the simple notification service and it tries to abstract away both the Google cloud messaging for Android phones and the Apple push notification service for iPhones. And it mostly abstracts it. It gives you a single endpoint but you still have to care about Apple phones versus Android phones. So they've got this concept of a platform application. Now a platform application you give it a name and you have to tell it what the back end is. And so Apple in their infinite wisdom make it incredibly hard for developers. Is there anyone here that actually writes any form of Apple apps? Do you think they make it easy or hard? No, not great. No, no comment. I can say whatever I like. So also if anyone has any questions feel free to ask as we go along because it will be great for padding out time. We've got... So the APNS sandbox is what Apple gives you for developing push notifications. So you can only use their production site, the APNS one which is the public one if you've got your app through the app store which is the only way most iPhone users are ever going to get it. As a developer I write on the laptop, I load my app onto the iPhone and I want to test push notifications. But I can't use the production one, I have to use the special sandbox one which has different credentials which means my website which is sending the push notifications has to send it to a different place. It's an entirely parallel system which can be really annoying. Now, Google, they'll let you do anything. You can upload anything to the store and you can use their production and push notification systems for your dev apps. It all works. From a developer point of view, it's awesome. So Amazon will then take these attributes and give you an Amazon resource name which is effectively what you need to call it whenever you talk to Amazon using their endpoints. So they then have this concept of an endpoint. Now what that does is it's the token from your phone and your resource of your application that you're talking about and it gives you another ARN that you need to then store. So I've now got my phone app and the phone knows what it is. Luckily, you can ask your phone are you an Android or an iPhone? And it seems to know which is great. What we then do is we make a post to an authenticated view inside my web app. And so locally it asks for the token for this phone and then that sends it up to the app. And then so what I've got then is I want to create an asynchronous task to register this phone for this user with Amazon. So what I wanted to do is we want it to be asynchronous. We don't want talking to Amazon or this external third party tool to slow down our response back when we're doing a post. So this is where we use Celery. So I like Celery because it had a plug-in for Django and that was awesome because that's what I was using. So Celery itself is a separate project for dealing with asynchronous queues. And it allows you to effectively inside your normal stream of writing Python code just call this task to be executed later. And it actually works really nicely. So it's got a simple queue that you can use in development but if you're rolling out to production whenever you run the simple queue it says, don't use this for production. It prints it out in the big warning at the top. It also will give you heaps of warnings if you have debug enabled. So defining a task for Celery is really easy but it has several gotchas. So the Celery task is just a simple decorator on a simple function. And the interesting thing about it is how you always have to refer to the task. It does some magic look up internally that I don't entirely understand but if you read the docs it says never use the relative imports when you're trying to bring in your tasks. So when I'm calling a task you see here I actually import the full path name for the task and it says always do that or it will break and won't work. It'll let you send it but when at the other end I think it does some form of introspection so when it tries to look for the class that it said it will do later it can't find it which is why you always give it the full actual name. What's that? Yeah, it's probably pickling. So what I've got here is I actually hook up the get an endpoint ARN on the post save thing that Django gives me on a particular endpoint. So what I do is when I post this thing to the when the phone sends the post to the app it will then create an instance in the database and it goes, oh, if you've created one so this is a post save hook if it's new and it doesn't have an ARN yet then fire off this asynchronous task and this is the bit that makes it asynchronous. There's just a dot delay. So the previous task said that get our endpoint ARN is a task so that's just the method. So now we just call that function with the delay and the delay just effectively says do it soonish and soonish is normally pretty quickly except when you first do it the first thing that happened to me is I did it and then nothing happened. So salary has a worker that you need to run which is the salary worker which is you get the collection of salary tasks when you bring in the Django salary collection of things. And production use, you effectively use the system whether system D or upstart or don't ask me on Windows or Mac what you would use because I deploy it in AWS to an Ubuntu machine at the moment it's running trusty so I'm using upstart and when I get around to tweaking it it'll go on to Xenial which I'll have to work out how system D works. So, Boto is another Python library and Boto is a Python library that was generated by Amazon for talking to all of Amazon services. And Boto 3 is the new hotness and I'm still using Boto 2 because I'm slow and that was only in beta when I was first writing my software. One of the problems of dealing with a lot of open source software is everything moves under you. You just have your requirements.txt done and you're working along and then suddenly all the libraries you are using get extra versions and then I've never managed to keep up with it I'm sure some people have got some ideas. But Boto 3 is both Python and TensorFlow 2.2.7 and three 3.3+. For talking to any of Amazon services so I only use it to talk to SNS but it also, that library will do everything from the elastic computing cloud S3, basically everything that Amazon offers is a Cloud endpoint you can access through this library. I only use a very small piece of it. So, the problem that I've got is GamesCancell We want to tell everybody, I want to make all the phones go bing and that means more sleep for me and less where is everybody when you turn up and no one else is there. This happens to people. So what we have is someone updates the event inside my web app, so the event is updated, so effectively that's all done through a post back to the website and that initiates an asynchronous task. But we don't always want to initiate that task straight away because people make mistakes and they might typo, and the number of times you've gone in and saved something and then you've gone to look at what you've just saved and you're like, ooh, I typed that wrong or this is the spit source. So you want to go back, edit it, and then save it again. So what I do is we put a delay on the asynchronous task. So what we can do when we fire off the asynchronous task, instead of just calling the delay function, they've got a slightly different signature that you can call for apply async where you give it your, effectively the data that you're going to pass into this function. Anything you put, as Meno just mentioned, it's probably, it's pickling all of this data, so anything you can pickle, you can send as args to the function and when it runs it asynchronously, it will grab all those args and pass it into the function. So you can give it a whole pile of stuff. So these are actually big dictionaries. And you can tell it to delay, and I believe the delay is mostly in seconds. So it's, hi, Richard. So what we've got is I normally have it delaying to five minutes, but ideally I wanted it to something that could be configurable later and possibly with the idea of someone goes, no, no, send it now because I don't want this five minute delay. That can happen later. So the idea here is that it's going to send this off in five minutes. So one thing I've found is that the error messages you get out of SNS are terrible. Generally what it'll do is internally it's just going to effectively fire off an asynchronous task internally to SNS to send something to the other cloud endpoint. So what you generally get back as a success or failure from this connection to SNS is, yes I've sent, yes I've told GCM to send the message you told me to send. And so it might not actually work, but you never see that in your log from what you're doing. Only the next time it might come back and next time you try to send to that endpoint it goes, no. But what, where the actual failure was, was the time before. So you can actually hook up failure notifications. So there's lots of help online if you do need to do that. And so I've now got it, at least for the development version when I was trying to work out why things weren't working, to send me an email for every delivery failure. So that was useful. And it told me my certificate was invalid. Actually the other one it told me was that the endpoint was invalid, but it didn't tell me why or how to fix it, it just went nah. So there's definitely issues where you have issues with push notifications and there are many places where it can fall down and they're not always easy to diagnose. One of the things that was problematic for me, and originally, well most recently, was actually getting the right APNS certificates. You have to have a Mac to do this. Mind you, you have to have a Mac if you're going to be making any iPhone apps anyway. But we had a lot of trouble initially of creating the right, setting the right flags on your app to say this app uses push notifications. And then creating the right certificates in the wonderful Apple portal that allows you to do that. And then grabbing those certificates, getting the right bits out of those certificates so we can put them in as credentials to pass to SNS to give back to Apple. It is quite a pain in the ass. APNS certificates also expire. They only last for a year, and so you're expected to recreate them and redeploy them and update your system regularly. Google ones don't. So again, Google make it easy, but you're going to, if you do have problems, I think it does become a bit harder. Endpoints become invalid, and this is one of the more recent pain points for me. So if anyone's doing this, I'd be great. I'd love to hear how you solved it. Google and the Android platform move reasonably rapidly. And just as I finished writing the Android push notification endpoint, Google deprecated the API I was using and said, no, now you have to use this other one. And what they do is they'll periodically say you need to get a new token for the phone to receive push notifications. They'll mark the old one as invalid. But the new way of identifying them, whenever I take that token and send it to SNS and get my resource back and then try and send a push notification for it, I always get the response back of it's an invalid token. So if I use the old way, it works. The old deprecated way works. The new hotness way that they say, that's used in all the examples, and they say this is the new way to do it, Amazon tells me the way is invalid. So if anyone's done this with Android and knows how to fix that problem, I'd really like to hear. Other issues that we had while we were doing this is what Apple and Android can support inside that push notification payload varies a lot. And it also varies greatly onto where you're going to stop caring about your iPhones. My development iPhone that I use is an iPhone 4, because I thought, what's the oldest one I want to sensibly look after? In an iPhone 4, you can basically send it in a push notification about 160 characters and no title and very little other information. As opposed to the new iPhone ones, as you can actually pass it a title as well. So you get both the information and a heading, which is quite nice. In Google, you can send it 4K of data, plus I think you can send it images now, because some of the push notifications, particularly on Pinterest, if someone pins something that you've got, you see the picture of the pin. I'm like, there's so much stuff there that I'm not using, but the variability is really huge in what you can do. And what I wanted to do, and initially what we did do, is construct the messages for the smallest possible end point. So at the moment, all of our messages fit into about one and a half lines of text on the screen, because what we say is, six events have been created, or this game's cancelled. And that's about as much as we say. Because also, as far as user experience, what we want the user to do is to click on it and go into the app, because that will actually pull down all the data, so it'd be nice. Making a push-enabled iPhone app is much more annoying than I feel it should be. Endpoints becoming invalid, and actually tracking and testing from the endpoint of development, you're working on your little laptop here, and you're trying to test your push notifications. You need to run up your app and the salary worker, and hook up all of your development credentials, deploy it to your phone, make sure your phone's pointing at the right app. So normally when you have your app, you're going to be pointing to some production service. So you need to have some way to say, no, no, no, point at that development one. So it registers with that so it can get the right push notifications. But the way in which everything communicates and hangs together seems a bit tenuous. But the other thing we wanted to make sure that we did is that when the phone, when you click on the push notification, we want it to bring up the right page in our app. So when they say this event's cancelled, you want to take them to that event when they click on the push notifications. So you need to send a little bit of extra user data associated with the push notification, which says, go to this page in this ID, which luckily, both of them do. But again, you can't send a huge amount of data. But yeah, it actually generally works most of the time now. So I'm kind of happy. And that's it. Any questions? Do you think it's, SNS is actually worth it? Is it more pain than just talking to the services directly? I'm not entirely sure. I think it probably is. I hadn't actually considered trying to talk to both of them individually. Just because I thought it was going to be a lot more work. And I had considered that Amazon SNS was going to be easier. Perhaps it would be interesting to try and go directly and probably get better delivery failure messages. No, I hadn't considered it. But you're making me think about it now. Yeah, thanks for sharing the journey and the pain. We ran into similar issues when developing mobile apps and we literally gave up on that. Because our user base literally was on mobile phones with an associated mobile number. And so we just reverted to SMS, used that. And I was wondering in your emerging application, do you have different channels where you say, okay, you select SMS, push notification, email, and whatever channel, or was that something where you deliberately said, like, no, we need push notifications, surf tab, that's all? We wanted push notifications because that's what most users with phones are used to. I had considered using enabling SMSs or emails as well. But that's always sort of phase two and three type delivery. And at the moment we're still in phase one of a whole pile of stuff. So we all agree that it would be a great idea, but we just don't have the development resource to attack all of the issues just yet. So what I really want is like half a dozen shit-hot programmers that want no pay. Thanks for that, two questions. Have you thought about sending out notifications via SMS for those who don't have smartphones or those who don't have data enabled on their smartphones? And do you have any logical reasoning why you think Apple make it such a difficult job to do what you're doing? Okay, yes, I have thought about SMSs and I would like to support it. Again, it will happen shortly. One of the things that SNS does support is it does support mobile phone endpoints. SNS actually wraps not just the push notifications, it also wraps SMS and email. So when you deliver your payload object, you give it a pile of keys. You say, this is the structure to go to GCM. This is the structure to go to APNs. And this is what you can send over an SMS. This is what we're going to email. And you can say, here's the massive payload, pick what you need to send. So we could construct the extra data and just have it registered for mobile phones. At the moment, our app hasn't got a way for people to register their actual phone numbers yet. There's no reason why we can't, except time and effort. So I'd like to, yes, but later. As far as what about Apple, I think that the whole idea of the Apple ecosystem is it's targeted for people to focus on them. And if you are always developing for Apple and you always have a focus on Apple, then you're sort of brought into their system. And I think for the people that everyone I've talked to that has done Apple apps, they say the first one or two is really painful and then it gets easier. For someone like me where I'm only doing one app and it's not my job to make Apple apps, all I feel is pain. So I think, again, it's going to come down to central control and direction that the company is choosing. Apple have decided to say, our developer push side of things is going to be completely isolated from our production side of things. And that is the same decision for any company, generally. If you've got a staging website or a development website, you don't want to share the same database as your production website. They don't always, it's not always a good idea. Whereas Google, I think, have gone just for a different approach. It's like make it easier for the developers. And that's why I think we saw rapid proliferation of a lot of Android apps in the early days when iPhones were at the smartphone. And maybe they made the decision because they wanted to make it very easy for people to develop apps for their platform. So I think Apple has made the more sensible choice if I was going to do that type of thing, but it just does make it harder for the developers. Well, really, wouldn't it be easier to do a text and that sort of thing? You don't need any apps. You can just text people, voicemail people, that sort of stuff. Probably not kind of voicemail people, but that would be kind of cool. But like you could just, the person constructs the text and then you go for the thing and then it would go straight to the person, people. Right, but what we have is every person with the application is looking at more than just receiving just the notifications have changed. They have an app that they can go to and see what are my upcoming events. Because you might not just have, this is happening right now or this has been added. But it's like, well, this was added two weeks ago and I need to look at the app. It's like, when's my game tomorrow? Or where am I supposed to be taking my daughter on Thursday? What times are hockey game? We could, but then I have to make two things and I'm lazy. All right, so we'll take two more questions here and here. Hey, cheers for that. I was just wondering if you have a web interface and what or plans to have one and what your other, like if you plug into an existing calendar on a phone. Right, so yes, there is a web interface. No, it's not as mobile friendly as I'd like it to be, meaning not. But we've thought about that and we had ideas about being able to provide feeds of information. You've actually got two different types of, you've got your producers of the information, which is going to be your clubs or your organizing bodies of people that schedule all the events. And you've generally got the consumers that need to care about what is my child doing, right? Because generally Kyker Eye Primary, for example, does a whole pile of sports I don't care about. My daughter was playing field hockey and I didn't actually really care when the other Kyker Eye team was playing. I just wanted to know when my daughter's team was playing. So yes, there is a web interface for it, both as a user and as an organizer. And it's not as mobile friendly as I'd like. I would like to get it that way. But then again, I'm not a front-end web developer. So maybe one day when it makes money, I'll hire someone to make it awesome. Second question was, eye call integration or call integration? Yes, that's definitely on the short term roadmap is to be able to. So you could just get a custom URL for you that you could then plug into your other calendars. So yes, I do want to have an eye call feed. Yep. How do you know that someone uninstalled the app and doesn't care of the notifications anymore? If someone uninstalls the app and doesn't enable it for push notifications, we never know that they have an endpoint. So you keep pushing, but you never know. No, when you start the app, effectively what it's going to do is it's going to ask the phone for a token. If you haven't enabled that app to have push notifications, it will fail to get the token. So we're not going to get the token, so we don't pass the token up to the server. They enable it once. Yep. As soon as the... Well, if they uninstall the app, the push notification will fail from SNS. That will mark that endpoint as bad. It's like a network family. No, I don't... You can't just stop making them. At the moment, because I'm stupid, at the moment, yes, it will keep attempting to do it, and it'll just record in the log file, oh, that one was invalid. One day soon, I would like to be able to mark them invalid and actually remove the invalid ones as we pass through, but it's not hurting me yet, and until it inflicts pain, I probably won't deal anything about it. All right, thanks very much, and thanks to our speaker, Tim. Cheers. Thank you.