 dinosaurs and dyliau. Lyn yng Nghymru. My name is Paul, and I'm a developer of Angelist for 200. Does anyone here know what 20 0 is? I know you do, you will. Okay, so for those of you who have no idea, 20만 is a web API that makes it easy for you to do SMS and voice through your software and the reason I'm here today is because there's quite a lot of applications. Here in this ambient camp who are actually using 20, has anyone got a field from from London They've set up an entire PSTN network, you can call people locally here for free, and they're using 20.0 for that. EMF camp are also providing SMS notifications through our platform as well. 20.0 was really good for doing these offline hacks with internet things technologies but also with normal applications that you might have. They allow you to bridge that gap between the PSTN network, which everyone has even in a dumb phone like this straight into your web applications. I want to show you how it works and give you some advice on what you can build with it and allow you to go ahead and use it, just to show you a really cool tool that you might want to use. How does it work? Well, it is an API. I'm sure you're all pretty familiar with how APIs might work, but the Twillio API works a little bit differently to a normal API. You need phone numbers, just like your phone in your pocket, in order to interact with Twillio, you need a phone number. You can provision this through our platform. With that phone number, you can then receive or send SMS and voice calls. These come into the Twillio Cloud and Twillio will then send your application a HTTP request. This is a concept often called a webhook, which is pretty ambiguous, but just consider it a request coming to your server. In that request, you're going to get a bunch of information about the phone call that's coming in, the text message, if it is a text message, and in some cases, location information. You can manipulate that data. All that Twillio wants back is a set of instructions. You send it a phone call and it's going to say, what do you want me to do with this phone call? You can forward that number. You can ask them to type in their pin number on their credit card, for example, with D2F tones. You can record their call. You could put them into a conference call. So that's how the application works. I don't really like slides, so instead I thought I would do a live demonstration. I'm going to build a Twillio app right now, and I'm going to get everyone to participate. So, could everyone take out your mobile phones? The field phones won't work on this before anyone thinks, I'm going to see if this will break it. The field phones won't work, unfortunately. If you have no mobile signal, complain to T-Mobile, because you're probably on T-Mobile like me, and I have no signal. The first thing I said that we needed to get was a phone number, so I'm just going to go quickly and grab that on twillio.com, and I'm going to go and buy a number. Now, we are in Milton Keynes, so I'm going to get a local phone number, which is 01908, I believe. Is that right? Anyone local? Yep, cool. Awesome. This will just grab us a bunch of phone numbers, which I can get hold of right now, so I'm going to go ahead and grab this one here, the top one, and click that, and that number now belongs to me. So you should be able to make phone calls and SMS messages into that, but it won't do anything yet because we haven't configured it, so I'm just going to quickly save this number in my clipboard because I'm going to use it later on. I'm going to set it up. So, like I said earlier, when this number receives a voice call or an SMS, it's going to make a request to a URL that you define, and this is a URL that points to your web server. At the moment they go to the demo links, which isn't really useful for us, instead I want to make it go to my web server running on my laptop right here, and if the demo goes on nice to me and the internet Wi-Fi holds up, we should be able to get some stuff happening. So that's just going to go to my website and a URL slash messages. Let's look at what that server looks like. That server is currently eight lines of code, and it does absolutely nothing. I'm using Python. Any Python fans in the room? Yes, that's great. Usually you get no hands up and I start crying and walk off stage. So this is using Flask, which is a micro framework for Python. You can build APIs and really little applications in it really quickly. So let's go ahead and set that route up. We do that in Python by saying app.root, throwing in the URL here, and we want to accept post requests again, and this is just going to link to a function which I'm going to call reply to message, which is probably going to give you a hint as to what I'm going to get you to do in a second. I'm not going to do anything with the request that I get in. Instead, I'm just going to return a string, and this string is literally just going to be XML tags, a specific collection of XML tags that we could twimle, which are basically instructions that Twitter would transform into voice calls and SMS messages. We always need to have a response tag, so I'm going to start that with a response tag like that, and if you're familiar with XML or HTML, you know we should close the tags as well. Because I will get you to send me an SMS message, I'm going to reply with an SMS message back. I'm going to say hello EMF camp. Here is a promo code, hack EMF camp. Does anyone want to shout out a random word, not a rude word, just to prove that it is working? Okay. Anyone? Ragworm. That's the word I was going to have in my demo, thanks. Right. Okay. So if we look at the server here now and I get everyone to send an SMS message to this number, you should get back a reply and we should be able to see the requests come in. So that number is 01908410541. Don't send anything too rude. Please. We have young people in the audience. We do actually this time. I usually say that there isn't. So we're getting the requests in at the bottom. You can see these post requests are coming in and you should get back a reply. Did anyone get a reply? Yeah. Awesome. Okay. So that is inbound stuff. That's pretty cool. That's pretty basic. But what about outbound? We can do this with a traditional API that we have. So we have a REST API. Again, I'm going to use Python for this because I like to use Python. It's my favorite language of choice. We have a helper library available. However, if you don't want to use the helper library, this is just a HTTP API. So if you're doing this on, say, some hardware, like an Arduino or a Raspberry Pi, and you just want to cull these requests, you can do that as well. And this is called from20.RestImport20.RestClient. The lectern is at a weird angle, so I'm having to type weirdly. And I'm just going to quickly instantiate this client. This is going to grab my credentials from my environment, which is basically your username and password. So this is all protected over under HTTPS. Who wants to see what messages are sent in? Who's now thinking I shouldn't have sent that root message in? Because I'm going to display it on the screen. Let's go ahead and say four message in client.messages.list. This is going to get all the messages that were sent to that number we had. And I'm just going to print the body of the message. So just message.body. Okay. Let's see what we got. This is going to make an API query to 20.0, and we're going to get back all these results. So we've got deep sea yak wrestling, interesting hobby, and then we've tried it myself. And we get the usual hello, 20.0s and stuff. Where is Sherman? Who is Sherman? I have no idea where he is. I'm sorry. Okay. So there we go. We've got messages. So 20.0 will log everything that comes in through your API, and you can access it. You don't need to store it yourself. We can also get phone numbers. So your phone numbers will now be in the 20.0 behind my secure gateway, and I can grab those. I'm going to use a list comprehension just to build an array of those numbers now quickly. Again, I'm just going to query the API and just grab the phone numbers into a list. Can everyone see that? Okay. It's pretty low down. There we go. And then we can just say the length of the numbers to see how many we've got. We have got 19 people who've text in. Okay. So let's loop through those phone numbers and let's do something interesting. Let's make a phone call out to you. I'm just going to do this in one line of code, and this is going to create a phone call to your number. It's going to come from my phone number. It's from underscoring Python because it's a reserved word, which is annoying. And I need to link it to a URL. This is exactly the same concept as we explained previously. We need to link this to a URL on our server. Let's link it to a URL slash voice. There we go. Okay. We haven't done that yet. So we don't need to install anything new in order to do voice stuff. We just need to add an extra root to our application. Again, it's voice. We always want to accept the post methods. That's usually the mistake people make. So remember that. And I'm going to call this your function method voice call. And again, I won't do anything interesting with the request this time. I'm just going to send back a plain old response. We do have in our helper libraries a way for you to programmatically build this if you don't want to maintain or write big long strings. So what can we do with voice? Well, we could play songs. So I could play the Star Wars theme tune or the Adventure Time theme tune down the phone to you, which is usually what I do, but I'm getting a bit bored of that right now. So instead, I'm just going to gather your credit card numbers and then say thank you very much. And then I could record how bad you thought that joke was and then play it back later on to see who I need to hunt down. I could get you all to dial through to a number, so I could get you all to forward straight through to a plain old number. Or what I could do, which I think I will do now, is I'm just going to put you all into a conference call. So this will put everyone who calls in into a conference call and you can have a chat afterwards. And just close those tags and we just need to give that tag a name. And you know what? Probably worth calling this EMF camp. So just save that. Drunk back here. And so this is going to, again, this is going to make a phone call to everyone who just dialed in. It's going to come from the 21 number we had. And when you answer, it's going to make a link to that URL, giving it a set of instructions which will put you all into a conference call. OK. Let's go ahead and see that fire off. So that's going to fire off now. 20 is going to do all the processing for me. I haven't had to install anything new and you should get some phone calls. And when you do answer it and speak to the rest of the audience. So we should be able to get them in in a second. Anyone? There we go. We've got the post voices coming in here. We can see and you should be able to have a chat. Is everyone in? Yeah. OK. Cool. So that is the basics of Twilio. That is how you send and receive SMS messages and place and receive phone calls with Twilio. I'm aware that most of you are probably in a conference call right now and ignoring me. So if you want to use Twilio at all during any of your hacks, there was a promo code I just fired out via SMS. I have it as well. If you want to do it here, come and grab me or Phil. We're in the bright red jackets. We would love to see the various hacks you're doing. That is everything I have for you. So if you have any questions, just shoot them to me now. Or I could actually probably SMS you my phone number later on as well. So thank you very much. Any questions? Yeah. So you could build. So if you ever call your bank and you go through all those telephony menu systems using DTMF tones. You can build that with Twilio. So you're just using the gather function, the gather tag. And when someone types in a number of digits, it will then make another request with those digits as a header in your HTTP request. You can just say, oh, this person type three. Okay, I'll forward them to the monkeys in the room to talk to them. So you can have that tree as big and as complex as you like it. There's no limitation. You can also do voice transcription as well. So you can transcribe what people have said into text and then you can use natural language processing to figure out what they've said. Cool. So the twiml has to be written in XML. I'm a Jason fanatic myself as well. You can also, the responses you get come in. So through the REST API, you can just find whether you want responses in XML or in JSON. But for generating the twiml, the markup is done in XML like that. It's a necessary evil. But it's laid out much semantically. It's laid out in a much nicer way, I think, for this type of thing. This would probably be the only use case where I'd say XML is better than JSON. So the granularity on location is based mostly on the country you're in. So if we're talking about the US phone numbers, their phone numbers are geographically based. If you're using local numbers here, like I used the 01908 number for Milton Keynes, I can infer from that number that the person is probably calling me from Milton Keynes. If it's through mobile in the UK, unfortunately I can't now. I just know that you're on a UK mobile. But I do know you're on a UK mobile. And I could intelligently make you call a UK number so that I wasn't making you dial. For instance, if I was providing a service in all of Europe, I could make you dial through to a UK number which would only cost you the UK number of rate instead of making you call, say, a French number or a Dutch number. It's a country based for that. And actually in the US it will pretty much say this person's in Atlanta or California. You can't know that. Cool. Any other questions? All right, brilliant. Well, if you want to have a chat with me afterwards, I'm in the bright red jacket. I will be around until tomorrow afternoon. Come and grab me and thank you very much for your time.