SQLServerCentral Article

Post a Twitter Status Update using T-SQL

,

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

Rate

3.18 (11)

You rated this post out of 5. Change rating

Share

Share

Rate

3.18 (11)

You rated this post out of 5. Change rating