Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Sending private messages to Facebook users

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 405
    Comment on it

    Many of us have this requirement of sending private message to your facebook friends and we usally struggle to get it done. The main reason behind this is that graph api provided by facebook does not provide this. We have to look for other option which has been provided by facebook but facebook is really strict with it , if you ever try to spam a user your application might get blocked so please use it with care:

    Below is the ruby code which can be used to send message to friends ,gem being used for this is :

    https://github.com/kissrobber/xmpp4r_facebook

    And the code we need to send message is :

    sender_chat_id = "-#{sender_uid}@chat.facebook.com"
    receiver_chat_id = "-#{receiver_uid}@chat.facebook.com"
    message_body = "body of message you want to send"
    message_subject = "subject of message you want to send"
    
    jabber_message = Jabber::Message.new(receiver_chat_id, message_body)
    jabber_message.subject = message_subject
    
    client = Jabber::Client.new(Jabber::JID.new(sender_chat_id))
    client.connect
    client.auth_sasl(Jabber::SASL::XFacebookPlatform.new(client,
       ENV.fetch('FACEBOOK_APP_ID'), facebook_auth.token,
       ENV.fetch('FACEBOOK_APP_SECRET')), nil)
    client.send(jabber_message)
    client.close

    *Note : Keep in mind that we have to add - infront of "-#{sender_uid}@chat.facebook.com" else the code want work.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: