How I created an instant phone auction with Kynetx, Twilio, Twitter, and Google Spreadsheets
This last week I attended the Utah Open Source Conference, and decided to pass along a piece of geek gear to a new owner. I wanted to sell to the highest bidder, and needed an easy way to make that happen. I did it, and it sold. And here is how I did it.
Step 1: Create a Google Form/Spreadsheet
Google spreadsheets have a feature that allow you to gather input with a form, with the results being entered into a spreadsheet. I created a form with two fields: Bid and Bidder.
I added a second sheet to the spreadsheet, and created two formulas. The first formula finds the max bid from the first sheet, and the second finds the Bidder from the row with the highest bid.
I then publish the sheet as a webpage, so I can pull that information into Kynetx app. When a new value is entered into the form, the values will be inserted into the first sheet, and the formulas in the second sheet will update with the high bidder information. This information is then published (with a delay of a minute or so) and available to the Kynetx App.
Step 2: Create a new Twilio Phone Number
I already had a Twilio account with a credit card added. If I didn't, I would need to create a free account, then add funds with a credit card. Twilio very generously gives you $30 in account credit to play with when you sign up, but I needed to purchase a number, and this requires a credit card.
I created the new Kynetx app at this point, even though we write it in step 4, so that I can find out the AppID, which I needed to configure Twilio. The AppID of my new Kynetx app was a8x72.
I added a new phone number, and set the inbound call and inbound sms webhooks to http://webhooks.kynetx.com:3098/t/a8x72.dev/callstart and http://webhooks.kynetx.com:3098/t/a8x72.dev/sms respectively. The .dev in these URLs causes the development version of my app to run, and callstart and sms are the event names that I'll write rules for in Step 4.
Step 3: Create a Twitter Account
I created an account called samsopenmoko, and then visited http://dev.twitter.com/apps to register a Twitter App and get the associated keys. Be sure to allow read and write access to twitter from this application. Note that you need both the consumer tokens AND the access tokens. These tokens are placed in the Meta block in our Kynetx Application.
Step 4: Glue it all together with Kynetx
Our Kynetx application has two sections, one which handles the phone call logic, and another that handles the sms logic. Here is the entire text (with redacted keys) of my Kynetx application.
Step 5: Ending the auction
When the bidding began to slow, I ended the auction by adding the following rules at the beginning of my application. As soon as I saved, no more bids would be accepted, and callers are informed of the auction close. I could have made this automatic based on a time event or other data, but I was lazy.
Calling last in the postlude ensured that no other rules would run, providing an early exit to the application.