Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Post a Twitter Status Update using T-SQL

By Michael Malmgren,

Introduction

Interesting and innovative uses of Twitter have recently emerged and many organizations are today trying to figure out how to best use social networking technologies. In this article I will demonstrate a hassle free way to post a Twitter status update using the Boomerang framework and few lines of T-SQL

To make a status update to a Twitter account using the Boomerang framework and MS SQL is a simple and straightforward process. As an IT professional you will interact with the Boomerang SQL database. Each table in the database has its unique function like Email Out, Twitt Out, Fax Out, File Out, Print Out, Email In and Twitt In. In addition to these tables representing services there is an Event Master table used for managing events and Event Status and Event log for status and transaction log.

In this example we will be using two different services: Twitter Out i.e. post Twitter status update and Email Out i.e. send email. The Twitter and Email out services is represented by the following tables Boomerang.dbo.OUT_TWIT and Boomerang.dbo.OUT_EMAIL.

Each instance of Boomerang may be associated with one Twitter account. To use the Twitter Out (and In) service in Boomerang you will have to authorize Boomerang to send and receive on behalf of a particular Twitter account. This is done by means of Open Authentication standard that is supported by both Twitter and Boomerang. 

If you are unfamiliar with the Boomerang framework or new to the Twitter Out (and In) feature I suggest the following additional reading Getting Started with Boomerang and Authorize Boomerang to post Twitter updates.

Basic Status Update

To make a status update to the Twitter account associated with Boomerang simply create a new event, insert the status update into table OUT_TWIT and then release the event.  

Example:

-- Declare Key's
declare @gKey uniqueidentifier; set @gKey = newid()
declare @jKey uniqueidentifier; set @jKey = newid()

--- Create new Event
insert EVENT_MASTER (gKey) values (@gKey)
-- Twitter Status Update
insert OUT_TWIT(gKey, jKey, Status) values(@gKey, @jKey, 'test message')
-- Release Event for processing
update EVENT_MASTER set Status=0 where gKey=@gKey

Result:

Multiple Jobs in one Event

The unit of work implemented by Boomerang is called Event. You can think of Event as an application task. Each event comprises one or more jobs. A job represents an actual unit of delivery, such as e-mail, or twitter status update. So, to combine two jobs simply add a second insert statement and appropriate keys. In the sample below a Twitter status update and a email notification, which are created simultaneously, will be processed.

-- Declare Key's
declare @gKey uniqueidentifier; set @gKey = newid()
declare @jKeyTwitt uniqueidentifier; set @jKeyTwitt = newid()
declare @jKeyEmail uniqueidentifier; set @jKeyEmail = newid()
declare @StatusUpd nvarchar(50); set @StatusUpd='test message no 2'

--- Create new Event
insert EVENT_MASTER (gKey) values (@gKey)

-- Twitter Status Update
insert OUT_TWIT(gKey, jKey, Status) 
values(@gKey, @jKeyTwitt, @StatusUpd)

-- Send notification email out
insert OUT_EMAIL(gKey, jKey, Subject, Body) 
values (@gKey, @jKeyEmail, 'Twitter Status Update', 'The following Twitter messages:' + @StatusUpd)
insert OUT_EMAIL_RECEPIENT(jKey, Email) 
values (@jKeyEmail, 'info@fuel9.com')

-- Release Event for processing
update EVENT_MASTER set Status=0 where gKey=@gKey

Result:

Conclusion

Boomerang takes away the chore of writing complex code to interface with Twitter and other notification infrastructure like e-mail, printers, file and fax servers. By means of the Boomerang framework IT Professionals can create robust and dynamic notification solution with a minimum amount of T-SQL code. As illustrated above we posted a twitter status update using five lines and twitter status updates plus a e-mail notification with a handful of additional lines. 

Learn More / References

Introducing Boomerang - A Notification Framework

Tracking/filtering messages in the Twitter stream

Configuring Twitter In and Out

Download above code samples

4 Ways Companies Use Twitter for Business

16 Examples of Huge Brands Using Twitter for Business

Resources:

twitt_out_sample2.jpg | twitt_out_sample2_5.jpg
Total article views: 2228 | Views in the last 30 days: 2
 
Related Articles
ARTICLE

Introducing Boomerang - A Notification Framework

Boomerang is a notification framework for IT professionals providing service oriented infrastructure...

FORUM

Post a Twitter Status Update using T-SQL

Comments posted to this topic are about the item [B]Post a Twitter Status Update using T-SQL[/B] Meh...

BLOG

Thoughts on Twitter

We hear a lot about social media these days:  Facebook, LinkedIn, Google+, Twitter, etc.  More and m...

FORUM

Introducing Boomerang - A Notification Framework

Comments posted to this topic are about the item [B]Introducing Boomerang - A Notification Framework...

BLOG

Andy on Twitter

Just prior to the 2009 PASS Summit I posted about giving Twitter a try, and thought I’d report back ...

Tags
boomerang    
notification services    
t-sql    
twitter    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones