Home » Technology » Internet/Web » TweedleD Back From the Dead Using Twitter OAuth

The Most Versatile VoIP Provider: FREE PORTING

TweedleD Back From the Dead Using Twitter OAuth

Twitter Direct Messages and SMS Instant Messages are great ways to send yourself important notes that you want to keep track of… privately. Today, we’ll restore TweedleD to the living and let you harness the power of Twitter and SMS to announce every call on your Asterisk® server with the name and number of the caller as well as the DID of the incoming call.

If you’re one of the gazillion handful of folks using one of our Twitter applications, then you awakened to an unpleasant surprise earlier this morning. Neither Tweet2Dial nor TweedleD would connect to Twitter! That meant you could no longer use Twitter to place Google Voice calls, to send Google Voice SMS messages, or to manage your Asterisk server. Nor could you send yourself direct messages when new incoming calls hit your Asterisk server. Unfortunately (for us), the Twitter folks have discontinued use of basic authentication to log into and use Twitter’s API. Instead, you now must use the more secure (and more complicated) OAuth authentication mechanism. Actually, this is a good thing in the grand scheme of things because it means you no longer have to give out your actual Twitter account name and password to anyone. So let’s move on to how to put Humpty back together again.

We’ve actually been wrestling with this a good long while. The basic problem is generating the necessary new credentials for use on servers that are tucked safely behind hardware-based firewalls. Without getting too deep in the weeds, here’s the drill. To use OAuth, you basically need two sets of credentials. First, you need your own (not ours!) application-specific credentials known in the Twitterverse as your consumer key and consumer secret. These are generated by Twitter and normally hide inside your application. They are never made public. You also need an access_token and access_secret. But these can only be obtained once Twitter generates a request_token that is passed back to your application. There’s also a request_token_secret that is used by Twitter to verify that you are who you say you are before the access_token and access_secret are provided. If this sounds complicated, you’d be right. Now add the fact that our particular Twitter apps are sitting behind a firewall on your server, and you can begin to appreciate why OAuth complicates things with apps running on private networks.

So here’s the deal. To use the new OAuth-compatible versions of Tweet2Dial and TweedleD, you’ll need four pieces of information for each of these applications: a consumer_key, consumer_secret, access_token, and access_token_secret. Because the two applications typically use two different Twitter accounts, you cannot interchange these four pieces.

The traditional procedure for getting these four pieces of data works like this. First, you go to the Twitter apps web site and register each application while logged into your Twitter account that will host the application. For each app, you must specify the following. In return, Twitter will provide a consumer_key and consumer_secret for the application.

  • Application Name
  • Description
  • Application Web Site
  • Organization
  • Web Site
  • Application Type
  • Callback URL
  • Default Access Type
  • Use Twitter for Login?

Second, you must create an application on the public web to log into Twitter using your new credentials. This log in process will produce the remaining pieces necessary to generate an access_token and access_token_secret specifically for you. Can you do all of this? Obviously, only you can answer that question, and here’s the best guide we’ve found to walk you through the process. Suffice it to say, unless you are a seasoned programmer, it’s a hairy procedure with lots of opportunities for disaster. But be our guest and try your hand at it.

What’s Plan B? The alternative to Step #2 above is to log into a special web site we’ve created to generate the necessary credentials for you. But this means you have to provide (and trust us not to store or use) your consumer key and consumer secret. You also don’t want someone looking over your shoulder while you’re obtaining the remaining credentials. Unfortunately, without your consumer key and consumer secret, we can’t obtain an access_token and access_token_secret for you. And without those, nothing works.

To get started, you’ll need to register your new application with Twitter. For this to work, the Application Web Site address and Application Callback URL in Step #1 need to point to our web site, not yours. Once you get the secret codes, you can change the web links for your application to any fake address you care to make up. Just don’t delete the Twitter app you’ve created.

If it makes you sleep any better, this isn’t your bank account we’re talking about, it’s a specific Twitter application, one that we happened to write for you. So, if you like Plan B and you’re comfortable with our assurance that none of your confidential keys or passwords are being harvested, continue reading. Otherwise, use your own devices for getting the four necessary credentials. Then you can download the new OAuth-compatible version of TweedleD, and you’re off to the races.

Today we’re going to tackle TweedleD and get it back in operation. In coming weeks, we’ll tackle Tweet2Dial as well.

TweedleD Setup. Let’s begin with TweedleD which lets you send Twitter DMs and SMS alerts to announce every incoming call on your Asterisk server. This tutorial assumes you previously have installed the original version of TweedleD. If not, start there. Now let’s proceed. First, you’ll need to register the application with Twitter.

Step #1 is to use a browser to log into the Twitter account that you plan to use to generate the Direct Messages. If you can’t remember which Twitter account you used to originally set this application up, log into your Asterisk server as root and find the $username entry near the top of nv-twitter.php in the /var/lib/asterisk/agi-bin directory. Your password for this Twitter account will be there as well.

Step #2 is to open a new tab with your browser and visit Twitter apps. Choose the Register a New Application option and fill out the form like this:

  • Application Icon: Your choice
  • Application Name: TweedleD
  • Description: Asterisk Incoming Call Announcer
  • Application Web Site: http://pbxinaflash.com/oauth/index.php
  • Organization: Your Name or Company Name
  • Web Site: http://anything-you-like.com
  • Application Type: Browser
  • Callback URL: http://pbxinaflash.com/oauth/callback.php
  • Default Access Type: Read & Write
  • Use Twitter for Login: Leave unchecked

Click the Save button once you’ve entered all the data and completed the Captcha code. Once your app is registered, call it up and write down your Consumer key and Consumer secret. By the way, if these ever get compromised, you can generate new ones. But it means you’ll have to repeat the rest of this exercise since the other credentials will change as well.

Step #3 is to visit our OAuth Credentials Generator web site using your browser. Now plug in your Consumer key and Consumer secret. Then fill out the Captcha code and click the Submit button. If you got the Captcha code right, you’ll see your entries redisplayed with an option to Login with Twitter. Just click on the link, sign in to Twitter if you’re not already signed in, and click the Allow button when prompted whether to Allow TweedleD access to your new web site. If you get some funky error message from Twitter, then you didn’t enter your Consumer key and secret correctly. Try again. Otherwise, you’ll then get a screen that displays some information about your Twitter account as well as your new Access Token and Secret. Write these down, too.

Access Token: 32438037iO5cYUq4h0BJD4Z6Un5phaZHZ2zJ4P4LQ2t6TX8fpU

Access Secret: PQrhUlM9nnJwIrYCNTF07ai3vlXgMD3uf3qmmWJp6o

Step #4 is to download and install the new TweedleD application. Log into your Asterisk server as root and issue the following commands:

cd /
wget http://bestof.nerdvittles.com/applications/TweedleD2.tgz
tar zxvf TweedleD2.tgz
rm TweedleD2.tgz
cd /var/lib/asterisk/agi-bin
nano -w nv-twitter.php

Step #5 is to configure TweedleD for use using your new Twitter credentials and your SMS email address. You’ll also need to choose whether to activate tweets, SMS messages, or both by setting $tweet and $sms to 1 if you want either or both of them activated.

If you’re activating Twitter, set $tweet=1 and fill in the 4 credentials that you wrote down previously: $consumer_key, $consumer_secret, $access_token, and $access_token_secret. In the $user4msg option, enter the Twitter account name to which the direct messages should be sent.

To activate SMS messaging as well, set $sms=1 and enter your SMS email address in the $smsaddress field using one of the examples provided.

Save the file, and you’re ready to try things out. Just make a call to your Asterisk server and the Twitter message announcing the call should arrive shortly thereafter. For syntax on other Twitter API calls, see the Twitter API Documentation. Enjoy!

Need help with Asterisk? Visit the PBX in a Flash Forum.
Or Try the New, Free PBX in a Flash Conference Bridge.

whos.amung.us If you’re wondering what your fellow man is reading on Nerd Vittles these days, wonder no more. Visit our new whos.amung.us statistical web site and check out what’s happening. It’s a terrific resource both for us and for you.


Special Thanks to Our Generous Sponsors

FULL DISCLOSURE: ClearlyIP, Skyetel, Vitelity, DigitalOcean, Vultr, VoIP.ms, 3CX, Sangoma, TelecomsXchange and VitalPBX have provided financial support to Nerd Vittles and our open source projects through advertising, referral revenue, and/or merchandise. As an Amazon Associate and Best Buy Affiliate, we also earn from qualifying purchases. We’ve chosen these providers not the other way around. Our decisions are based upon their corporate reputation and the quality of their offerings and pricing. Our recommendations regarding technology are reached without regard to financial compensation except in situations in which comparable products at comparable pricing are available from multiple sources. In this limited case, we support our sponsors because our sponsors support us.

BOGO Bonaza: Enjoy state-of-the-art VoIP service with a $10 credit and half-price SIP service on up to $500 of Skyetel trunking with free number porting when you fund your Skyetel account. No limits on number of simultaneous calls. Quadruple data center redundancy. $25 monthly minimum spend required. Tutorial and sign up details are here.

The lynchpin of Incredible PBX 2020 and beyond is ClearlyIP components which bring management of FreePBX modules and SIP phone integration to a level never before available with any other Asterisk distribution. And now you can configure and reconfigure your new Incredible PBX phones from the convenience of the Incredible PBX GUI.

VitalPBX is perhaps the fastest-growing PBX offering based upon Asterisk with an installed presence in more than 100 countries worldwide. VitalPBX has generously provided a customized White Label version of Incredible PBX tailored for use with all Incredible PBX and VitalPBX custom applications. Follow this link for a free test drive!

Special Thanks to Vitelity. Vitelity is now Voyant Communications and has halted new registrations for the time being. Our special thanks to Vitelity for their unwavering financial support over many years and to the many Nerd Vittles readers who continue to enjoy the benefits of their service offerings. We will keep everyone posted on further developments.

Some Recent Nerd Vittles Articles of Interest…