Jump to content

Twitter Hook


rke211

Recommended Posts

So i have added a custom field for twitter usernames for my clients

 

Ive then made a hook that posts on their twitter telling them they have a support reply this is simple enough but im just wondering if their was an easier way than searching the db to get the custom fields etc.

 

require_once($_SERVER['DOCUMENT_ROOT'].'/twitter/twitteroauth.php');
function reply_twitter($vars) {
$consumerKey = '******';
$consumerSecret = '******';
$OAuthToken = '******';
$OAuthSecret = '******';
   $ticketid = $vars['ticketid'];
$ticket = mysql_query("SELECT * FROM `tbltickets` WHERE `tid` ='".$vars['ticketid']."'");
if(mysql_num_rows($ticket)){
	$t = mysql_fetch_array($ticket);
	if($t['userid'] > 0){
		$user = mysql_query("SELECT * FROM `tblcustomfieldsvalues` WHERE `fieldid` = '6' AND `relid` = '".$t['userid']."'");
		if(mysql_num_rows($user)){
			$u = mysql_fetch_array($user);
			if($u['value'] != NULL || $u['value'] != ""){
				$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret);
				$message = "@".$u['value']." You have a new support ticket response from @DuckHost";
				$tweet->post('statuses/update', array('status' => "$message"));
			} // end value check
		} // end user rows
	} // end userid check
} // end ticket rows
} // end function
add_hook("TicketAdminReply",1,"reply_twitter");

Link to comment
Share on other sites

https://dev.twitter.com/

 

login through your account and setup an application as read and write :P i cant emphasis that enough i spent 20 minutes with the right code not realising i simply had the wrong setting on twitter lol

 

But thanks i figured i know a few people who use twitter a lot more than they check their emails so why not take advantage of that fact ive had to recode my twitter feed though so it doesnt post on our homepage "@blah You have a new support ticket response from @DuckHost" was easy enough but just worth baring in mind

Link to comment
Share on other sites

Apologises for the double post but a kinda crucial thing i just realised

 

Twitter dont allow double posting so it wont let you post

 

for instance

 

@client you have a new support ticket response @twitter

 

then post another one

 

@client you have a new support ticket response @twitter

 

which means we need a work around now at first i thought yeh just stick the ticket id in and that fixed it for one instance atleast so after that the only other option to make it unique is to stick the time in it or something similar i suppose there is always the option of some really long if statement that has a lot of different ways of saying the same thing but i just stuck the time in so here is the new one

 

require_once($_SERVER['DOCUMENT_ROOT'].'/twitter/twitteroauth.php');
function reply_twitter($vars) {
$consumerKey = '****';
$consumerSecret = '****';
$OAuthToken = '****';
$OAuthSecret = '****';
   $ticketid = $vars['ticketid'];
$ticket = mysql_query("SELECT * FROM `tbltickets` WHERE `id` ='".$vars['ticketid']."'");
if(mysql_num_rows($ticket)){
	$t = mysql_fetch_array($ticket);
	if($t['userid'] > 0){
		$user = mysql_query("SELECT f.id, v.value FROM `tblcustomfields` AS f, `tblcustomfieldsvalues` AS v WHERE f.id = v.fieldid AND f.fieldname = 'Twitter' AND v.relid = '".$t['userid']."'");
		if(mysql_num_rows($user)){
			$u = mysql_fetch_array($user);
			if($u['value'] != NULL || $u['value'] != ""){					
				$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret);
				$message = "@".$u['value']." you have a new support ticket response #".$t['tid']." from @DuckHost ".date("H:i");
				$tweet->post('statuses/update', array('status' => "$message"));
			} // end value check
		} // end user rows
	} // end userid check
} // end ticket rows

} // end function
add_hook("TicketAdminReply",1,"reply_twitter");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated