powered by Jive Software

How to write chatbot as plugin?

With IQ packets all is clear. I can register a plugin as an IQHandler.

But what about Message packets? Where I can plug my own packet handler?

I’‘m not sure what you mean with “chatbot”. For me this is just another user with a “normal” JID, something like bot@yourserver.tld. I’‘m not sure if you’‘d want to realize this in the server - I’'d go for a client library in that case (smack?) and do it that way.

If you really need/want to realize it in the server I see this options:

  • create a component, similar to the broadcast plugin. You’'d use something like hello@yourbot.yourserver.tld as JID in that case

  • Implement your own MessageRouter, catching every messages for and handling them however you like.

I’‘m rather new to Jive, so I cannot tell you the “better” way - and I don’'t know what exactly you want to archive. But I hope this helps you finding the right solution.

I’'m not sure what you mean with “chatbot”.

I mean server-side chatbot, because it may use server API (see http://www.jivesoftware.org/forums/message.jspa?messageID=95002#95002).

If you really need/want to realize it in the server

Yes. Really.

I see this options:

  • create a component, similar to the broadcast plugin. You’'d use something like hello@yourbot.yourserver.tld as JID in that case
  • Implement your own MessageRouter, catching every messages for and handling them however you like.

There is a problem.

hello@yourbot.yourserver.tld is not a normal Jabber account. It is fake account. Ergo, i cannot add it in shared roster group. How i can notify the user on presence of the server-side chatbot?

Besides I would like to have an opportunity to modify all messages passed through my message handler.

I see this options:

  • create a component, similar to the broadcast

plugin. You’'d use something like

hello@yourbot.yourserver.tld as JID in that case

  • Implement your own MessageRouter, catching every

messages for and handling them however

you like.

There is a problem.

hello@yourbot.yourserver.tld is not a normal Jabber

account. It is fake account. Ergo, i cannot add it in

shared roster group. How i can notify the user on

presence of the server-side chatbot?

I don’‘t understand the problem here. hello@yourbot.yourserver.tld is a valid JID imho - so I’‘m not sure why you shouldn’‘t be able to add this name to the shared groups. I haven’'t looked into them in detail, but I think there are only checks for valid JIDs?

Changing the presence: PresenceManager.setOnline() looks like what you’'d want there?

Besides I would like to have an opportunity to modify

all messages passed through my message

handler.

I think that’‘s exactly what the MessageRouter class is for, if you want all messages. But I might misunderstand your emphasis or whole point. If you want to process all messages for this component only: That’'s what processPacket should do. If you whole point was, that you want to modify the messages: What about copying/resending an altered packet using ComponentManager.getInstance().sendPacket(thePacket)?

Just had a look at your userlist plugin in the mentioned thread: Nice work, really.

Just one question:

The broadcast-plugin uses

ComponentManager.getInstance().sendPacket(thePacket);

while you use

+Session session = SessionManager.getInstance().getSession(origin.getFrom());

try {

session.getConnection().deliver(reply);

} catch (UnauthorizedException uae) {

// ??

}+

Any reasons for that? Is there any advantage/disadvantage in either method?

I don’'t understand the problem here.

hello@yourbot.yourserver.tld is a valid JID imho - so

I’‘m not sure why you shouldn’'t be able to add this

name to the shared groups.

It is a valid JID, but is not a valid account.

Admin console does not allow to add invalid account into shared roster group.

Changing the presence:

PresenceManager.setOnline() looks like what

you’'d want there?

Sorry for my english.

I wanted to ask this:

How to me to inform users, what in our network there is a chatbot? In fact shared roster groups do not work with illegal accounts.

Just had a look at your userlist plugin in the

mentioned thread: Nice work, really.

Just one question:

The broadcast-plugin uses

+ComponentManager.getInstance().sendPacket(thePacket

);+

Yes. I know.

while you use

+Session session =

SessionManager.getInstance().getSession(origin.getFrom

());

try {

session.getConnection().deliver(reply);

} catch (UnauthorizedException uae) {

// ??

}+

Any reasons for that? Is there any

advantage/disadvantage in either method?

I don’'t know.

It is a result of lot of experiments (I for the first time have seen Messenger from within). And it works.

Besides I would like to have an opportunity to modify all messages passed through my message handler.

I think that’'s exactly what the MessageRouter class is for, if you want all messages.

I cannot replace MessageRouter with my own, because it is core server module.

But I might misunderstand your emphasis or whole point.

I want to develop some filtering capabilities, e. g. for use in censoring system.

I want to develop some filtering capabilities, e. g.

for use in censoring system.

This problem was discussed here

http://www.jivesoftware.org/forums/thread.jspa?threadID=13724

But with no results.

Okay… Somehow we messed the order up in this thread.

I understand that you want to read/get/modify any message - and I don’‘t think that you can do that in a component for now. At least I don’‘t see a way right now - but you might be able to work around this by adding a custom route? Just guessing right now - I’‘m still looking at the routing parts of JM and ponder how I’'d give it a try.

Concerning the chatbot/shared roster problem:

I’‘m still not sure what the problem is… If you have the component (external plugin) yourbot.yourserver.tld, what is the problem in adding it to the shared roster? Can’‘t try it right now, but even if yourbot.yourserver.tld doesn’‘t work, why don’'t you add Bot@yourbot.yourserver.tld? That would be a complete JID and should work.

Considering the problem of “making users see the bot”: You should be able to compose a message from that JID. I hope that does the trick - but again, I’'ve not tested it.

Concerning the chatbot/shared roster problem:

I’'m still not sure what the problem is… If you have

the component (external plugin)

yourbot.yourserver.tld, what is the problem in

adding it to the shared roster? Can’'t try it right

now, but even if yourbot.yourserver.tld

doesn’‘t work, why don’'t you add

Bot@yourbot.yourserver.tld? That would be a

complete JID and should work.

Should work, but not work for me.

Admin console talk:

User(s) not added successfully.

info@userlist.zencomru is not a registered user.

Hey fefelov,

Currently groups can only hold users of the local server. So when adding a new user to a group you just need to specify the username and not the complete JID. I’'ll file a Jira issue to improve the error message and make it clearer.

Thanks,

– Gato

Are there any plans to extend this? Maybe I miss a point with the components, but as far as I know they are able to filter messages which are send to their specific subdomain. But how should I “animate” a client to send a message to this subdomain, if I can’‘t add a component to a group and make it visible as a pseudo user, nor I can put a user into a subdomain. E.g. a userJID can’'t be user@filtered.localhost

What I try is to have a “fake user” in the roster of the other users without having a real client behind this JID. But after stepping through the messenger code it seems like a heavy task to fake this as a user is only displayed in a roster if he has a session and the session relies on a connection object which is far to much down in the hierarchy to fake. My hope was to use a component to accomplish this but this stops as soon as I try to make it somehow visible to the clients.

But anyway, messenger is a nice piece of software.

Markus

Markus,

That’‘s a good point and I agree it would be very nice to be able to at least put component JID’‘s into a group. We’'ll think about how hard that might be to add.

Regards,

Matt

You would make me very happy with that.

Thanx, Matt.

That’'s a good point and I agree it would be very nice

to be able to at least put component JID’'s into a

group. We’'ll think about how hard that might be to

add.

Sounds good, but there is yet another suggestion. I need to write component, that will filter all texts passed through server, e.g. vcard data, messages, etc. How to do this?

Currently groups can only hold users of the local

server. So when adding a new user to a group you just

need to specify the username and not the complete

JID. I’'ll file a Jira issue to improve the error

message and make it clearer.

Thanks, Gato.

I do not need more clear message on this error. The opportunity to add the component’'s JID in shared roster group is necessary for me.