Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
picnik #1
Member since Apr 2011 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: Get sender from message
Hello,
I am trying to code a faceboook chatbot which will whenever it's running send me the chat message as a email.
As soon as the email is sent I want to tell my chat partner that is been sent

My problem is: how can I get the sender/nickname/facebook id  just from the message?
Message.Nickname doesn't return anything ):

Here's my code
using System;
using System.Collections.Generic;
using System.Text;
using agsXMPP;
using agsXMPP.protocol.client;
using agsXMPP.protocol;
using agsXMPP.Collections;
using agsXMPP.protocol.iq.roster;
using Microsoft.Win32;

namespace JabberClient
{
    class Program
    {
        static bool _wait;
        static void Main(string[] args)
        {
            Console.Title = "Facebook Chat Bot v1";
            Console.ForegroundColor = ConsoleColor.White;


            /*
             * Login
             *
             */
            Console.WriteLine("Login");
            Console.WriteLine();
            //Console.WriteLine("Fb Username: ");
            //string JID_Sender = Console.ReadLine() + "@chat.facebook.com";
            string JID_Sender = "*******@chat.facebook.com";
            //Console.WriteLine("Password: ");
            Console.BackgroundColor = ConsoleColor.White;
            //string Password = Console.ReadLine();
            string Password = "****";
            Console.BackgroundColor = ConsoleColor.Black;


            Jid jidSender = new Jid(JID_Sender);
            XmppClientConnection xmpp = new XmppClientConnection(jidSender.Server);

   
            try
            {
                xmpp.Open(jidSender.User, Password);
                xmpp.OnLogin += new ObjectHandler(xmpp_OnLogin);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

           
            Console.Write("Wait for Login ");
            int i = 0;
            _wait = true;
            do
            {
                Console.Write(".");
                i++;
                if (i == 10)
                    _wait = false;
                Thread.Sleep(500);
            } while (_wait);
            Console.WriteLine();

           

            try
            {
                xmpp.OnMessage += new MessageHandler(xmpp_OnMessage);
            }
            finally
            {
               
            }
           
            //prevent the window from closing...
            Console.ReadLine();
        }

        static void xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            Console.Write(msg.Nickname + " " + msg.Body);
        }
       

        // Is raised when login and authentication is finished
        static void xmpp_OnLogin(object sender)
        {
            _wait = false;
            Console.WriteLine("Logged In");
        }

    
        }
    }
}

Right now it's only giving me the message text without the sender


Thanks in advance
Avatar
picnik #2
Member since Apr 2011 · 4 posts
Group memberships: Members
Show profile · Link to this post
You can delete this thread, I just found out how to get the username/sender ;)
Message.From.User
Avatar
picnik #3
Member since Apr 2011 · 4 posts
Group memberships: Members
Show profile · Link to this post
I am sorry for the tripple posting but I ran into another problem.

How do I return the Message.From.User-attribute? onMessage is a void so it's not able to return anything.

I also tried to create a static Jid but whenever I was trying to change it within onMessage by doing this:
Jid fb_id = Msg.From.User;
id = fb _id   //id is the static var declared right before the main() function
it says: "Can't convert "string" into "agsXMPP.Jid" " (well this is not exactly what it says, but I can't copy/paste because my Visual Studio is german ;) )
Avatar
Alex #4
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I am German as well.  So no problem to read your stacktraces.
There is a constructor in the Jid class which accepts a string and builds a Jid object from it.

Alex
This post was edited on 2011-04-10, 13:14 by Alex.
Avatar
Alex #5
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The Nickname is included in the roster only. When you login then you receive the roster. Put all the roster items in a dictionary, then you can lookup the Nicknames by jid.

Alex
Avatar
picnik #6
Member since Apr 2011 · 4 posts
Group memberships: Members
Show profile · Link to this post
In reply to post #4
Quote by Alex:
There is a constructor in the Jid class which accepts a string and builds a Jid object from it.

Thank you very much Alex :)
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS