how to add new buddy in roster in xmpp - xmpp

Hi i am using smack.jar.I am able to connect with gtalk using it.Using Roster.getentries() i can get my buddy list.But how can i add new friends to my buddyList.Is there any API smack exposes to add new users??
Thanks

I've been using this to create new contacts in a standard XMPP server (can't tell about gtalk):
Roster roster = xmppConnection.getRoster();
// jid: String, user: String, groups: String[]
roster.createEntry(jid, user, groups);

In XMPP, adding is adding to your roster + subscribing to the user. Updating is just adding the user to your roster. Keep in mind the minutiae.

Related

Openfire ConversationID has changed after logout

I'm developing a chat app that use XMPPFramework and Openfire Server. When I (usn2) send message to usn1, a message has been created in ofMessageArchieve with conversationID. But after logout and login again, when chat, the new conversation has created (see image below), but I want to add this message to exist conversation. How can I do this?
Code to send message:
let msg = XMPPMessage(type: "chat", to: XMPPJID.jidWithString(getJIDFromName(stateID)))
msg.addBody(message)
msg.addAttributeWithName("id", stringValue: stream.generateUUID())
stream.sendElement(msg)
Although I changed Openfire as #Shoaib Ahmad Gondal suggested. It still happens
MessageId and ConversationId is not same. MessageId generates for each message you send but ConversationId generates based on users & session(maybe). To keep them same you have to modify message archive plugin or develop new one.

how to retrieve group list a user is a member or admin in xmpp?

I am working on the chat application. I want to implement the group chat functionality in the web client. I have done things till group create and basic configuration and joining the group. I want to know if there is any extension developed Or any other way by which I can get the list of group which user has created or is member of. e.g in watsapp, any body can create group and add me as a member. how to konw which room i have been added as a member, is there any iq request in xmpp muc.
Your iq is close. You need to address the room, not the server.
var iq = $iq({
type: 'get',
from: 'userjid#jabber.server.com',
to: 'roomname#conference.jabber.server.com'
}).c('query', { xmlns: 'http://jabber.org/protocol/disco#items' });

Connect outbound call to a lync conference

Is it possible to, given a UCMA application (using application or user end points), to create an outbound sip call and then join this call to an active audio conference on lync server?
If so, how would I do that?
I know one can create an outbound call and also I know it's possible to join an endpoint to an active conference, but has anyone done this two things at the same time?
Thanks,
Assuming you're creating a new Conversation with your UCMA application (instead of getting an incoming call to your app), you can connect this new conversation to a conference.
The trick to to use the conversation's ConferenceSession object to join the conference, rather than calling to it directly, and then establishing the call without a target uri.
Note that you need to impersonate the conversation if you attempt to make multiple calls to the same conference from the same application endpoint.
For reference of the BeginJoin, see this MSDN page: ConferenceSession.BeginJoin.
var conversation = new Conversation( <your application endpoint> );
conversation.ConferenceSession.BeginJoin("<your conference uri>", (joinresult) => {
conversation.ConferenceSession.EndJoin(joinresult);
// User has joined conference here.
var call = new AudioVideoCall(conversation);
call.BeginEstablish(new AudioVideoCallEstablishOptions(), (establishresult) => {
call.EndEstablish(establishresult);
// Call is established with conference now.
});
});

Access muc roster from an ejabberd module (disco_items?)

I'm building an ejabberd module to send carbon copies of messages to an external RESTful API. Everything works okay, and requests to that API are sending POST params with Sender, Recipient and the message Body.
I'm triggering the user_send_packet and user_receive_packet hooks for this, and I can extract the params (Sender, Recipient, Body) from the packet:
Sender = xml:get_tag_attr_s("from", Packet),
Recipient = xml:get_tag_attr_s("to", Packet),
Body = xml:get_path_s(Packet, [{elem, "body"}, cdata])
For group chats (MUC) I'd also like to send the MUC roster (participants) in a parameter, but I don't know how to access them.
Is there an event for this? Can anyone point me to some documentation?
Thanks in advance!
It seems that you want to get MUC participants of specific room.
You need to look at mod_muc.erl and mod_muc_room.erl.
I'm not sure which version of ejabberd you use, so I will explain based on latest ejabberd.
After getting pid of room by calling
mnesia:dirty_read(muc_online_room, {Room, Host})
you can call
gen_fsm:sync_send_all_state_event(Pid, {get_disco_item, From, Lang}, 100)
or use similar code. User list is in the reply.
If you don't like reply format, you may want to add custom handle_sync_event to mod_muc_room.erl .

How can I get the user jabber Id in a chat room using AnyEvent::XMPP?

There is a way to get the user's nick(roomName#domain.com/nick) in the chatroom according to the document, but how can I get the user's real jid(name#domain.com/resource_name)? is it possible according to XMPP protocol?
You can unless the room is anonymous. The Jabber protocol makes it possible that people in a chat room may be anonymous so that you cannot get back to their real JID. This is also why it provides a private message chat within the rooms, so you can still private message someone who has done this.
I have some code that does this in Bot::Backbone::Service::JabberChat:
# Figure out who sent this message
my $from_user = $room->get_user($xmpp_message->from_nick);
# Prefer the real JID as the username
my $from_username = $from_user->real_jid // $from_user->in_room_jid;
my $from_nickname = $from_user->nick;
See AnyEvent::XMPP::Ext::MUC::User and AnyEvent::XMPP::Ext::MUC::Room for more details.