• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ General Support (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Notification to twitter when a user enters chat

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
4 posts • Page 1 of 1

Notification to twitter when a user enters chat

Postby demian » Sun Feb 24, 2013 11:21 am

Hi,

I want to give my phpfreechat driven site a little boost and want to post a message to twitter when a new user is entering the chat.

This is already working, but it is a general message posted on twitter saying a user has come in.
I would like to send this message only after someone actually filled in his name and is active in the chatroom.

Were could i include my msg2twitter.php in the phpfreechatcode, i think the ajaxcode need to parse a string to my phpscript, how?

Cheers,
demian
Last edited by demian on Mon Feb 25, 2013 1:20 pm, edited 4 times in total.
demian
Member
 
Posts: 14
Joined: Tue Sep 09, 2008 7:40 pm
Top

Re: retrieve a user name of user entering chat

Postby demian » Mon Feb 25, 2013 1:40 am

I think i found a way to do it.

In log.class.php ( http://phpfreechat.svn.sourceforge.net/ ... iew=markup )

Everything is logged in the logfile.
I can easely include msg2twitter.php after writing to the logfile and parse the username to the script from there.
demian
Member
 
Posts: 14
Joined: Tue Sep 09, 2008 7:40 pm
Top

Re: retrieve a user name of user entering chat

Postby demian » Mon Feb 25, 2013 11:12 am

Cool, it works!

I did it this way:

in : /src/proxies/log.class.php insert following code after file_put_contents....

Code: Select all
    file_put_contents($logfile, $log, FILE_APPEND | LOCK_EX);
        }
      }
    }
   
   //Message 2 Twitter - Insert from here
 
   if(preg_match('/joins My room/',$param)) {
   
      $name = explode(" ", $param);
    
         $consumerKey = "yourkey";
         $consumerSecret = "yoursecret";
         $accessToken = "yourtoken";
         $accessTokenSecret =  "yourtokensecret";
         $today = date("F j, Y, H:i:s");
         require_once '../twitter.class.php';   
         $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);   

         try {
            $tweet = $twitter->send($today . ': '.$name[0] .' has entered the chat and wants to talk with you! Surf to www.yourdomain.com');

         } catch (TwitterException $e) {
            echo 'Error: ' . $e->getMessage();
         }            
   }

   //Message 2 Twitter - End
   

    // forward the command to the next proxy or to the final command


Also, put those files in /chat/src

twitter.class.php
oAuth.php

And ofcourse,

create an application at dev.twitter.com
Generate your keys,
Change settings : POST instead of GET and
Permissions to Read & Write

Don't forget to activate logging the chat to a logfile otherwise the log.class.php won't run. (i guess)

And that's it. :mrgreen:
demian
Member
 
Posts: 14
Joined: Tue Sep 09, 2008 7:40 pm
Top

Re: Notification to twitter when a user enters chat

Postby demian » Mon Feb 25, 2013 1:24 pm

Just another thought.

It is quite simple to send an email in a similar way to users who signed up for an email notification, you only need to make a sign up form on your site and include some code with email adresses to send a message to.

Only thing, be carefull with mailing a big list, it could be considered as spam, but it will give users more privacy instead of following the twitter account.
demian
Member
 
Posts: 14
Joined: Tue Sep 09, 2008 7:40 pm
Top


Post a reply
4 posts • Page 1 of 1

Return to General Support (v1.x)

Who is online

Users browsing this forum: No registered users and 43 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub