 I'm actually going to talk a little bit about integrating Elixir with telephony, working with Asterix PBX, kind of like adhesion if you're familiar with adhesion. I'm also going to show you an auto administration package that I wrote. So I'm actually going to take you through, depending on the time and glitches and stuff, I'll actually build up a little voice survey application. So we'll configure some questions in the database and then we'll actually call it to have it actually text the speech and read the questions, allow you to pick choices and then do some reporting on that. So who am I? I already said my name, a bunch of information in there. We've been doing Elixir now for almost two years. I've been doing it for about a year and a half full time. Last year I was at the conference I presented on a telephony gateway that I wrote in Elixir. Since that, I've ported a software licensing system that I had written originally in Rails. I've ported that over to Elixir and Phoenix. I had another call-out emergency call-out system that we use at local hospital. If it's an all hands on deck, they hit a button that calls all the employees, say there's an emergency, you've got to come in, press 1 to accept or 2 to decline. I had a lot of problems getting that working with Rails and Adhirsion. I ended up almost by necessity rewriting it in Elixir and it works awesome now. Another exciting project, we're just starting a soft client, a soft phone project where we're going to do a phone in a browser using WebRTC for the media and I'll be doing all the phone signaling over Phoenix channels. So that one's just getting started and it's pretty cool. So what I'm going to talk about today is this voice survey application. So database with some stuff in there and sort of read out the questions and then touch tone responses. This is, although it's a demo now, it is a product that we're looking at and I'll probably be productizing this soon. So it supports multiple surveys, multiple choice questions and some very simple reporting right now. So it's a Phoenix, Elixir Phoenix application. Our product that we have runs MySQL so I wrote this in MySQL using Echo and an auto administration tool that I wrote called XAdmin uses Astrix PBX and another package I wrote called Spekex which is inspired by Ruby's Adhersion and then underneath that it uses XAMI and Earl AGI, AMI for the third party call control and the AGI for in-call handling. So is that readable up there? So a pretty simple data model here. So we have a model for survey basically has the name of the survey which we'll read out and then the number that's called in to activate that survey. So the program different numbers that comes in and it'll pick the survey based on what number they called. A question with the name, an answer or sorry choice. So choice belong to the questions and program the digit that they'll press to respond to that key to that choice and answer when they take the survey. So the seeding is the model I chose to actually represent someone sitting down and taking the survey and in there we'll know what number they called from and then obviously answers when they pick the choices. So we're going to attempt to build this. So I've got some instructions I posted all this up on GitHub. So I timed it, it was going to take too long to do it all so I prepped a little bit, I did the depths and depths get and all that stuff. You can't see it, Command F1. Oh, Command F1, okay, let's make that a little smaller. So as you can see it now, it's a little bit cut off. So create a new project, mix Phoenix new, then go in, set up the database, run mix echo create which I've got to do and then I've already prepped these models. So we have the survey model, actually I already talked about that in the picture. So basically we've got to go in and do a couple edits, we have to just set up the data, has many relationships here. So by default the commands to create the models, actually I didn't really talk about that. So mix Phoenix, gen model, choice, choices and then the key and the name, the seeding is the caller name and then the server ID is a reference to servers and so on. So fairly basic, hopefully you guys have a little bit of experience with Phoenix or I might be going over your head. So in this file we had to add these two relationships. In this file we had to add the two has many relationships for the choices and the answers. In the choices I had to add the answers and in the seeding I had to add the has many for the answer. And for the answers that was, actually I just added the keys in the required fields. Then obviously so we put in the X admin dependency, run depth, get all that fun stuff and the next step will actually be to install X admin. So I will go to the console here, showing up okay, I might want to shrink that a bit. So first thing let's actually create the table, the database, create and then we will do the migration, I always misspell that. And then we will install X admin, so mix admin.install and it gives some messages to do some configuration so we will pop back to the source code now and we will take a look at that. So in the config it populated some, the templates uses Hamel and then some other settings and that looks good. In the dev that looks good there so everything looks good there and then if we go back to the instructions here, there is also some router stuff that we have to set up so we have to set up the routes. So we go back to the router and I will just uncomment this stuff, I kind of prepped it up a little bit to save some time, terrible typing. So two lines, so use the X admin router and then just use this DSL or macro for setting up the routes. We save that thing and we should be almost ready, let me just, oh I got to go back to, here we go. So there is some configuration that we have to add, I have that there so I will do that. And we should be ready to go. So let's run, let's actually just check the document and make sure it didn't miss anything. Oh yes, one more thing. So we have to add the paging into the repo. Okay, so let's go back to the source code, go into the repo and uncomment this line and put the console and let's try to run it, okay, and we cross our fingers. Okay, so that's the basic template that Phoenix creates and then we should have a admin namespace bummer. Okay, so something mixed up, so I missed a step somewhere. Okay, so this is where I do a fallback. Let me just go through the rest. I've got a version here that should be working, so this was, I won't try to debug this right now. I missed the configuration step somewhere. So let's go back to here, so okay, so the next step is to actually create the resources. So we'd run a command like this. So admin gen resource and then survey and then we run that for our question and we run that for the choice and then we run that for the seeding and did I do answer yet? So if we go back to our source, we see what that did. So we have this admin folder under the web directory and it basically creates this just dummy or blank file. So typically I namespace with things with X admin in the middle and then resource, register resource. So these are all generated and basically what that will do is that will then produce a GUI that is pretty straightforward. So go back here. How am I doing for time? Got a bit yet. Okay, so, okay, so I'm going to just go into this working version. This choice is default. I have a little bit of fancy stuff here that I was going to work into. So let's just comment that out. Okay, so that's the survey page and then the question we can comment that out too. Okay, so let's just save that and let's run this thing. Oh, thank you. Perfect. Okay, so we're here. Go running that and let's see what that looks like. This doesn't work, I'm going home. Okay, so with those blank files, when you set up the resource with the mixed task, you get basically this blank shell. So seedings, choices, so the menu is automatically populated. So let's go in and create a survey. So we'll call this elixir cons. And 5555 for a calling number. And so we create that and then we can go in and create a question. So a new question. Enjoying the conference. What happened there? Oh, that's a glitch. Thank you. And then we'll create a choice. Answer one, four, yes. Now, this is a pretty basic GUI. It could be optimized quite a bit, right? But just to demonstrate, no. Boom. Okay, so now we have that configured. And we should be ready to go. So we have a telephone here. And we cross our fingers. One more step. I found a glitch this morning. And I don't know the idea why this is doing this, but it seems like it wants to be built. Where did my phone go? Come to the elixir cons survey. This survey has one question. Press the star key to repeat the question. Let's start. First question. Are you enjoying the conference? You have two choices. Press one, four, yes. Press two, four, no. Please choose. Five is not a choice. Please try again. First question. You have chosen. Yes. Press one to confirm or any other key to repeat the question. First question. That concludes the survey. Thank you for participating. So there, that's how I'll just quickly go back and touch on a couple things here. And then so we have, okay. So I added a little bit of code. I'll show you this code in a minute. But from a reporting perspective, I just extended the show page for the surveys to actually list the questions and then the results. So as we take the survey, this will be updated. So I'll just take you through that code really quick. That a little bit smaller. Okay, so the survey, I'm still in the old file. So if I look at the admin survey file, so I added a show handler. So in the show handler, call the attributes table so that generates that first panel. The second panel just generates the questions. And then the third panel, which is more complicated, the reporting panel. Basically, I go in there and get a seeding count. Check to make sure there's something there. And then I just using a DSL to map out the HTML. Create a table head with question responses in percent. And in the body of the table, I just calculate it based on the values. So extending using Xadmin to extend and make the GUI a lot more wretched, you can do that. And I guess I didn't show you the call controller. So the other piece obviously here is the call controller. There are two components to that. First of all, you need a router. So you need a router, so in here you can actually, when the call comes in, you can look at the number, who it's to, or who it's from, and so on. Then route this call to different call controllers. So in this case, I'm just doing a default. I'm routing everything to the survey controller. And in the survey controller, basically we have a DSL for handling the call. So it automatically, when the call comes in, it's answered. And it comes and runs the run call back with a call object. And then you can answer that call. Then I run my function for running the survey. And then I hang up the call and I terminate running the survey. I go out to the channel and I get the two value in the channel. That's the number that was called. I get the calling number. And then I create a new survey, sorry, I get the survey based on the two value. So I go in query and I get the survey model. I insert a new seeding for this. And then I say welcome to the survey. Then handle questions. Basically handle questions just sets up the initial prompt. Survey has so many questions, yada, yada, yada. Interrupt so that you can actually skip the prompt and don't have to listen to the whole annoying thing. Then I just iterate over the questions and build and call handle question, which we'll do the menu. I'll show you in a second and then just say an exiting prompt. So the menu prompts just go through and build, let's say it's the first question, the last question. And then I go through the database through the choices, get the names, build that up, all backwards. Please choose and then I reverse it. And then you come into the fun stuff. So that was the build menu prompts, then I build a matcher. So I take the digits, the available choices for that particular question, put them all together in a charlist. And then I call this menu API with the call object. All the prompts or phrases that it's going to read a timeout value in a tries. And then you can match on, in this case I'm matching on all the valid entries. And it'll run this anonymous function with the press. I go in and I take a look at it, call a validate question to do that second menu to say, is this what you want? And if it's OK, I build an answer, set up the settings, insert it in the repo, match on a star to repeat the question, handle an invalid press, and handle a timeout. And of course it's going to run this menu for the number of retries right here for three. So it would repeat it three times and then it would fail out. And then the validate question is just another little menu that says, press one. So that's the code that takes to run the survey. And then the only other thing is the configuration for that, dev.exe. So there's two pieces of configuration you need here. So set up the AMI links, point it to the Astrick server, and set up the AGI to allow the callbacks. And that's basically what it takes to build a voice survey application. So in closing, like I said, another year gone by since conference last year, we're still going strong with Alexa. Got to a point in our company where I don't have to sell it anymore. It basically has sold itself. So now when I say, well, I'm going to build something in Alexa, there's no question. OK, cool. Or I say, I'm going to build something. And my business partner says, are you doing it in Alexa? So yeah, no. And it was a big hurdle to actually get the first product done in Alexa. I actually moonlighted it for a long time. And he thought it was a great idea. But when it was time to say, I'm ready to cut it over. I'm ready to throw away our C version and replace it with a Lixar, it's like, no, I don't think so. And so it took a little while. But I don't have to worry about that anymore. Phoenix Rocks, I love Phoenix. Well, Lixar is cool. But now I've really enjoyed working with Phoenix. I've seen great progress in the community, the community is getting bigger. We're starting to see a lot more packages out there, which is exciting. Still a ways to go. Obviously, the app that I ported over from Rails, it used Active Admin, Rails, and Adhesion. So I went to port it over, I thought, OK, well, Rails, Phoenix, that's not bad. But Active Admin, well, there is none. So OK, I've got to write that. And then the whole Adhesion thing, there wasn't one of those, so I had to write that. But now I've contributed those back to open source, so it's kind of exciting. There's so a long way to go on XAdmin. It's kind of in a not much better than a prototype stage right now. I'd love some help on that. So if anyone's looking to contribute to some open source, let me know. And SpeakX has a long ways to go, too. So I've got some of the DSL in place there, but there's a lot more of the DSL to implement. And I look forward to seeing you guys next year. All right. Thank you.