powered by Jive Software

ANN: Alpha launch of a bot that uses Smack and Google Talk

Thanks to the developers for getting Smack to work with Google Talk.

I was eagerly waiting for this, and cranked out a bot that uses Smack to interface with several different sources of info.

It can search on Google, pull up stock quotes, search a specialized javadoc index, search a specialized wikipedia index, or search Amazon.

The point is to have a small form factor interface to multiple sources of info w/o requiring a browser.

The code and operational issues are alpha quality, but if someone wants to try it out please do so - the bot name is searchmorph@gmail.com, and to use it you just add it as a friend and give it the string “?” for help, or see my search blog for more info:

http://www.searchmorph.com/wp/ (note: the full URL to the post didn’'t render right so I have to put in a shorter URL here)

enjoy,

Dave Spencer

PS

I’'m sorry if announcements are inappropriate for this forum.

Very nice. I like it. One suggestion: on the javadoc search, try to make the search query the most important. I tries searching “System” and the System class came up fourth out of 6 results. I suggest making the most relevant result either first, or last (as the last comes up closest to the actual frame in the chatting window)

Dave,

Nice job! One thing it would be cool to add eventually is a bot framework to Smack. That would make it even easier for people to create XMPP-based bots.

-Matt

he he ! cool !

It’‘s a pity that you implemented the bot with Google Talk server because it doesn’'t have s2s protocol.

And I cannot connect to talk.google.com:5222 couse I’'m behind a firewall

This type of bot is exactly what I have been looking for. However, how hard would it be to implement this as a Jive Messenger plugin?

It would be really nice to have a bot like this running directly on an internal Jive Messenger server, so users could add something like bot@internal.domain.com and query it internally/directly.

This type of bot is exactly what I have been looking

for. However, how hard would it be to implement this

as a Jive Messenger plugin?

It shouldn’‘t be hard at all, actually (we’‘ve done something similar). You’'d register the plugin as a component and then listen for incoming messages and respond.

-Matt

Thx for suggestion. I agree that java.lang.System should appear first.

I wrote the query expansion code for the javadoc search I maintain on searchmorph.com and I use the same code in the ''bot.

If you do the same search there you get to:

http://www.searchmorph.com/kat/search.jsp?s=System

and if you hit the “explain” link next to the match for java.lang.System you go to

http://www.searchmorph.com/kat/explain.jsp?id=44169&url=java.sun.com/j2se/1.4.2/ docs/api/java/lang/System.html

And I know it’'s sort of cryptic, but it shows that the query “System” expanded to:

+(system xurl:system0.1 title:system2.0 description:system0.1 keywords:system0.1) j14:y3.0 j15:y1.1 apache:y^2.0

Which translates into: “title matches are worth more, and matches in jdk1.4 or jdk1.5 are worth more”.

Now it’'s unfortunately more involved debugging to determine why it was 4th instead of 1st, but at least you can see the intent!

Re a bot framework.

What would be nice is also some kind of auto-keepalive, and auto-connect, though I’‘m new to jabber and I don’'t know if these are required - they were when I tried to interop w/ AIM and Y!.

Also, if your resonses have to be portable to different systems, then you need some notion of how the client renders - does the client accept html? raw URLs? how do you do bold (for goggle it’'s a * before and after the text, for other systems I think you do ****

), etc…

I’‘m thinking of making a Bot… How do you make the bot accept all additions to people’‘s member lists? I don’'t wan to have to manually allow everyone to add the bot to thier list!

Re: “How do you make the bot accept all additions to people’'s member lists?”

It’'s funny - I thought I would have to write code for this but it seemed to happen by magic…

As far as I know I don’'t have any explicit code for this.

  • Dave

It’'s funny - I thought I would have to write code for

this but it seemed to happen by magic…

As far as I know I don’'t have any explicit code for

this.

Smack is configured by default to just accept all roster requests.

-Matt

Awesome, thanks

I am already write exchange rate plugin of Google Talk ,

usage:

1: add hail-fellow of SearchRate@Gmail.com

2: command format (re: us/china 、 us/uk 、us/Japan and so on )

because of close port 5222 , i’’ am used exodus test.

Test Result:

16:26] us/china

8.0849

uk/china

14.6013

us/France

5.3002

France/china

1.5249

Ok, so Smack will accept roster additions automatically. However, I can’‘t get my bot to accept incoming chats without creating a chat with that person. I thought I just needed to add a PacketListener to my bot, but that doesn’‘t seem to be enough. Even with connection.addPacketListener(…), only packets coming from the user I’'ve established a Chat with reach the processPacket method

Hey Brian,

It is hard to say what’'s going on without actually knowing your code. Anyway, I would suggest checking the filter you are using for the packet listener. Make sure that the packet that you want the listener to receive matches the condition. Try opening the Smack debugger window to analyze the received packets.

Regards,

– Gato

allright, my packetListener now works sometimes[/i]

The filter was[/i] a FromContainsFilter("@"), because I figured all from values contain the @, and I want to accept everything. That didn’'t work. I changed it to an empty String and now I can get in a max of 2 messages before it locks up…

allright, here’‘s my relevant code. It’'s not Threaded… do you think that may be the problem?

import …;

public class GoogleMUCHub implements PacketListener

{

private boolean verbose;

private GoogleTalkConnection connection;

private Chat convo;

public void processPacket(Packet packet)

{

convo = new Chat(connection,packet.getFrom());

Message message = convo.nextMessage();

String from = message.getFrom();

String body = message.getBody();

System.out.print(verbose ? timestamp() + “<” + from + "> " + body + “\n” : “”);

}

private String timestamp()…

public GoogleMUCHub(boolean verbose)

{

this.verbose = verbose;

try

{

System.out.print(verbose ? “## Connecting to talk.google.com\n” : “”);

connection = new GoogleTalkConnection();

           System.out.print(verbose ? "## Logging in as gtalkmuc@gmail.com\n" : "");

connection.login(“gtalkmuc”,"…");

}

catch(XMPPException xmppe)…

System.out.print(verbose ? “## Accepting incoming chats\n” : “”);

Chat.setFilteredOnThreadID(false);

connection.addPacketListener(this,new FromContainsFilter(""));

}

public GoogleMUCHub()…

public static void main(String[] args)…

}[/code]

If you can find the reason why this is locking up, I would much appreciate it. I think tomorrow during my freetime in Comp Sci I’'ll try threadding it to see if that makes it work, assuming nobody here finds my problem first

Hey Brian,

I think this is a logical problem rather than a threading problem. Your listener already received the packet so I don’'t know why is it that you are creating a new chat and asking to process the next[/b] message. If you are using the correct filter then the listener will get the desired packets to process. In your case you are just printing the message that you got so your listener can do that with the received packet sent as a parameter instead of asking the Chat for the another message.

Asking for another message is the reason why the application is being locked. My guess is that the other party just sent 2 messages.

BTW, you may want to post this question in a new thread if it wasn’'t answered yet.

Regards,

– Gato