Ejabberd hook for banned account - ejabberd

Our hook on muc_filter_presence does not receive calls when user is banned and forced to leave chat room. Is this expected? If so, is there other hook we could use for "user ban" callbacks?
We are using ejabberd 18.04.

The muc_filter_presence is designed to filter presence stanzas sent to the room. In the case of a kick, it's the room the ones that sends it, so it makes sense this event isn't called.
When kicking (or banning) a room occupant, I see this event is called:
ejabberd_hooks:run(
leave_room,
<<"localhost">>,
[<<"localhost">>,
<<"room1">>,<<"conference.localhost">>,
{<<"baduser">>,<<"localhost">>,<<"tka1">>}]).

Related

NATS - just one subscriber to take action for published event in a microservicearchitecture

I'm new to NATS and have read all the examples for:
https://nats.io/documentation/concepts/nats-messaging/
I'm in Microservciearchitecture where in microservice-Y (MSY) need to store some information published from other microservice-X (MSX) I have 2-10 instances of MSY so when changes are made in MSX and MSX-instance publishes event I want that only 1 instance of MSY should save information so not all of them save the same data.
I have read Request-Repy:
https://nats.io/documentation/concepts/nats-req-rep/
but there seems that all of instances receives message (and will handle it) even if it is point-to-point and reply is handled just for the one instance that is quickest to reply
Is this correct or have I missunderstood example?
If I only need that 1 instance of MSY should handle given message (store data in db) what can I do to acheve this?
Use queue groups. If you have multiple subscriptions on the same subject with the same queue group, only one of the members of the group will receive the message.
Check this out: https://nats.io/documentation/concepts/nats-queueing/

Restrict feathers service method to user for external but allow any queries for internal calls

I want to restrict calls to a Feathers service method for externals calls with associateCurrentUser.
I also want to allow the server to call this service method without restricting it.
The use case is that through this service then clients use a lock table, all clients can see all locks, and occasionally the server should clear out abandoned rows in this table. Row abandonment can happen on network failures etc. When the server removes data then the normal Feathers remove events should be emitted to the clients.
I would imagine that this should be a mix of associateCurrentUser and disallow hooks but I can't even begin to experiment with this as I don't see how it would be put together.
How would one implement this, please?
Update:
I found this answer User's permissions in feathers.js API from Daff which implies that if the hook's context.params.provider is null then the call is internal, otherwise external. Can anyone confirm if this is really so in all cases, please?
It seems to be so from my own tests but I don't know if there are any special cases out there that might come and bite me down the line.
If the call is external params.provider will be set to the transport that has been used (currently either rest, socketio or primus, documented here, here and here).
If called internally on the server there is not really any magic. It will be whatever you pass as params. If you pass nothing it will be undefined if you pass (or merge with) hook.params in a hook it will be the same as what the original method was called with.
// `params` is an empty object so `params.provider` will be `undefined`
app.service('messages').find({})
// `params.provider` will be `server`
app.service('messages').find({ provider: 'server' })
// `params.provider` will be whatever the original hook was called with
function(hook) {
hook.app.service('otherservice').find(hook.params);
}

Ejabberd right hook to find the user login

For detecting the user login the right hook looks like user_available_hook from the name. But this post Intercept login/logout ejabberd uses set_presence_hook. Which hook is the right hook?
You should use user_available_hook as it is called only on the first available presence of the user. set_presence can be called in some cases on presence change and it is probably not what you want.

Run Dial & Say at the same time on Twilio?

When a user calls my number, I wish to have Twilio <Say> something to them while <Dial>ing another number, the issue is, I can only seem to get it to do one or the other (I.E. Say, then dial (Delaying the dial), or, dial, then say (Not saying until the call is over)). What I want is either of the following (First one would be preferable, although answers to do both would be the best (In case I need the opposite one in the future/someone Googling)):-
Initiate the call to the new number AND start saying "Lorem ipsum...", if the say finishes first then silence until the call is picked up, if the phone number picks up first, let the say finish then transfer them/combine the calls.
Initiate the call to the new number AND start saying "Lorem ipsum...", if the say finishes first then silence until the call is picked up, if the phone number picks up first, cut the say command off and instantly transfer/combine the calls.
Thanks!
Twilio evangelist here.
There is no way to do this using just Twiml as Twilio processes Twiml sequentially so its going to finish the <Say> before moving on to the <Dial>.
You could combine Twiml with the REST API to do this however. In the same HTTP request where your generating the TwiML with the in it, you would also make a call out to the REST API to have Twilio start an outbound phone call.
Twilio would <Say> what you want to Caller A while dialing Caller B. When Caller B answers, put them into a conference. Once Caller A finishes listening to the <Say> put them into the same conference.
This way, regardless of who gets their first, Caller A or Caller B, either will wait for the other. You can use the StatusCallback parameter to detect if Caller B never answers and in that scenario redirect Caller A out of the conference.
Hope that helps.

offline_message_hook: does not get called when one sends an offline message

I am developing, chat application for android using ejabberd as XMPP server. I want to send GCM push notification, when user is offline. For that I am creating new module in ejabberd, registerd offline_message_hook, but this function gets called only when somebody starts typing and finishes typing. Below are the only packets passed to this hook. Although, user receive message when he/she comes online.
Packet: {xmlelement,
"message",
[{"type",
"chat"},
{"id",
"purple7d4d0773"},
{"to",
"xxx#rakshith"}],
[{xmlelement,
"paused",
[{"xmlns",
"http://jabber.org/protocol/chatstates"}],
[]}]}
Packet: {xmlelement,
"message",
[{"type",
"chat"},
{"id",
"purple7d4d0773"},
{"to",
"xxx#rakshith"}],
[{xmlelement,
"composing",
[{"xmlns",
"http://jabber.org/protocol/chatstates"}],
[]}]}
Two things about hooks in ejabberd:
1) The callbacks are called always in order, the order is defined by the priority you specify when registering it.
2) If a callback return 'stop' it prevents the event to be propagated to the rest of the listeners on the chain.
What is happening is that the ejabberd offline module is listening in the offline_message_hook, the same than your code. It handles the message, and returns 'stop', so your code isn't executed.
(your code do receive the message for the chatstates notifications because those are ignored by the offline module, and so it don't stop the chain in those cases).
You probably wants your code to be run before the offline storage module. Just remember to not return 'stop' so the offline module has the oportunity to store the message.