XEP-0191 not working with ejabberd server - xmpp

In my iOS chat application I am using ejabberd server to work with XMPP framework. I am trying to block a user using XEP-191. It is sending all the stanza correctly and I can see the user, I am blocking in the blocking list. But still I can see their presence, send message etc:
[_id: E8C458AB-DFC0-4C11-B91F-CF8FAB1911CA, _xmlns: jabber:client, __name: iq, _type: result, _to: user1#localhost/22895732401453270657994362, _from: user1#localhost, blocklist: {
"_xmlns" = "urn:xmpp:blocking";
item = {
"_jid" = "user2#localhost";
};
}]
I have also tried XEP-0016, thats also not working.

Related

create Structured Message with wit.ai

How can I take advantage of the navigation templates from the facebook messenger with wit.ai?
At wit ai I created a fully functional bot with the Structured Messages.
The issue that I'm experiencing is that when I connected the wit ai bot to facebook the structured messages don't disappear.
Is there any way that I can fix that?
you will have to send the elements of structured message to facebook when you send message.
Wit.ai will set the structured elements in response objects, its your responsibility to pass it on to facebook send api.
for example for quick replies wit.ai send it as response['quickreplies'] you have to access it and send to facebook as an array with key quick_replies and extra elements
def send_text_fb_message_with_quickreplies(recipientId, msg, quickreplies)
qr = []
quickreplies.each do |i|
reply_hash = {}
reply_hash['content_type'] = 'text'
reply_hash['title'] = i
reply_hash['payload'] = i
qr.push(reply_hash)
end
Bot.deliver(
recipient: {
id: recipientId
},
message: {
text: msg,
quick_replies: qr
}
)
end
send_text_fb_message_with_quickreplies(request['sender_id'], response['text'], response['quickreplies'])
with something similar code you can convert quickreplies from wit.ai to facebook compatible quickreplies
I am adding a little customized answer based on library you are using:
In the library you are using change https://github.com/hunkim/Wit-Facebook/blob/master/facebook.js file and is function fbMessage
Check if msg.quickreplies is present, if it is present do processing and make it facebook compatible format like i did in ruby code above.
post that change
message: {
text: msg,
},
to
message: {
text: msg,
quick_replies: object_you_created
}

Triggers in Parse Server using Swift

Recently, I was tasked to do a simple chat app for iOS, using Swift.. So, I have a parse server ready and running! All I want to know, is how to use triggers..
Let's say I have opened a conversation and I just received a new message. How can I get it, without constantly checking for new messages? I saw that cloud code is probably the way to go, but if it is so, is it practical? I mean, if I have 5000 users and they are constantly chatting, will it perform well?
Thanks in advance!
You want to use Parse LiveQuery component.
Add Live Query to your server's config:
let api = new ParseServer({
...,
liveQuery: {
classNames: ['Test', 'TestAgain']
}
});
// Initialize a LiveQuery server instance, app is the express app of your Parse Server
let httpServer = require('http').createServer(app);
httpServer.listen(port);
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);
Install Parse LiveQuery library as a pod to your project (pod 'ParseLiveQuery').
Subscribe for events:
let myQuery = Message.query()!.where("user", equalTo: PFUser.currentUser()!)
let subscription: Subscription<Message> = myQuery.subscribe()
Handle events:
subscription.handleEvent { query, event in
// Handle event
// This callback gets called every time an object is created, updated, deleted etc.
}

Getting repeated calls on facebook-messenger webhook

I have successfully setup a facebook-messenger webhook. Until yesterday I was able to send and receive messages as well. But today, when I am sending one message from user, I am getting multiple calls at server webhook POST API. They never seem to stop.
Do all of those calls have the same content or are they different? You could log the exact message string that facebook sends to you and see what they include.
For example there's a message delivery callback that informs you that the user received the message. The JSON looks like this:
{'delivery': {'mids': ['mid.146174459xxx:30a42600a95exxxxx'], 'seq': 429, 'watermark': 146174459xxx}, 'recipient': {'id': xxxxxxxx}, 'sender': {'id': xxxxxx}}
Edit: It could also be the case that your are not confirming incoming calls with a http status 200. If facebook receives an error from your webhook the message will be sent multiple times.
Figured it out. I was sending response to every communication that came from facebook. So I ended up responding to ACK messages as well. In turn one more ACK came. Thats why it led to infinite loop.
In this page we can find different object structures for messages recieved:
text
{
"object":"page",
"entry":[
{
"id":PAGE_ID,
"time":1457764198246,
"messaging":[
{
"sender":{
"id":USER_ID
},
"recipient":{
"id":PAGE_ID
},
"timestamp":1457764197627,
"message":{
"mid":"mid.1457764197618:41d102a3e1ae206a38",
"seq":73,
"text":"hello, world!"
}
}
]
}
]
}
Message-Delivered callback
{
"object":"page",
"entry":[
{
"id":PAGE_ID,
"time":1458668856451,
"messaging":[
{
"sender":{
"id":USER_ID
},
"recipient":{
"id":PAGE_ID
},
"delivery":{
"mids":[
"mid.1458668856218:ed81099e15d3f4f233"
],
"watermark":1458668856253,
"seq":37
}
}
]
}
]
}
So, for differentiating we can refer to entry[0].messaging[0].message this exist only in user sent message. Callback or postbacks do not contain this part.
Check for this, before responding. If it exists, respond, otherwise dont.
My problem was similar but I was getting Multiple Message delivery posts. After a few hours of frustration, I realized that Message Delivered callback is called every time the message is delivered to EVERY DEVICE. So, if you are logged into both web and mobile app, the callback would be called twice.
When working with messenger of facebook you need to take in account two things after you send the message :
A) Message Delivery
B) Message Read
Since you are working with webhooks this will be trigger everytime one of the events happen (receive a message , deliver the message you sent , the user read the message). So if you activate for example message_deliveries in your webhook and you send a message as action , you will end up in a loop.
The proper way to handle this is in the base code. PHP example :
// Skipping delivery messages
if (!empty($message['delivery'])) {
#Do something here if you want
continue;
}
// Skipping read messages
if (!empty($message['read'])) {
#Do something here if you want
continue;
}
Hope it helps !

Smack service discovery without login gives bad-request(400)

I am trying to discover items that a pubsub service provides. When I log into the target server, I can get the response successfully. But when I connect bu do not login, it gives a bad request error.
This is the code:
ConnectionConfiguration config = new ConnectionConfiguration(serverAddress, 5222);
config.setServiceName(serviceName);
connection = new XMPPConnection(config);
connection.connect();
connection.login(userName, password); //!!!when I remove this line, bad request error is received
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items;
try {
items = discoManager.discoverItems("pubsubservice." + serverName);
} catch (XMPPException e) {
e.printStackTrace();
}
Is there a way to discover items when the user is not logged in, but the connection is established?
No, you must authenticate to send stanzas to any JID in XMPP (otherwise they would not be able to reply to you, since they wouldn't know your address).
Perhaps one option for you is anonymous authentication. Most servers support it, and it creates a temporary account on the server for you, with a temporary JID. You don't need a password, and login time is quick.
#MattJ is correct and you could try using anon login. That will get you part way there.
Your current request will only get you the nodes though, after which you will have to get the items for each node. It would be simpler to use PubsubManager to get the information you want since it provides convenience methods for accessing/using all things pubsub.
Try the documentation here, the getAffiliations() method is what you are looking for.
BTW, I believe the typical default service name for pubsub is pubsub not pubsubservice. At least this is the case for Openfire.

How to query the roster using JSJAC XMPP client

How can I query full roster using JSJAC XMPP client? I have tried following function for this, but it does not work:
function getRoster(con){
var roster = new JSJaCIQ();
roster.setIQ(null, 'get', 'roster_1');
roster.setQuery(NS_ROSTER);
con.send(roster);
}
Instead of con.send, try:
con.sendIQ(roster, {result_handler: function(aIq, arg) {
var node = aIq.getQuery()
// do something with roster
});
You need to have a callback that fires when the roster is returned. To be complete, set a error_handler as well, in case an IQ error is returned or you time out.
sorry for commenting on such old question, hoewever this pops as #1 result in google on 'JSJAC roster' and the above answers didn't worked for me. i don't know whether something changed in the JSJaC API, however i was receiving iq errors 'service-unavaliable'. i had to use this code instead:
var rosterRequest = new JSJaCIQ();
rosterRequest.setType('get');
rosterRequest.setQuery(NS_ROSTER);
connection.send(rosterRequest);
(so no domain setting and no id setting - just the type, and namespace).