Project

General

Profile

Send push notification with every message

Added by S E 7 months ago

I am wanting to send a push notification to Azure Notification Hubs whenever a new message is received by the server. I've never done any development on tigase, so I'm completely new to this. What would be the best way to go about doing this? Would using this Java REST wrapper be what I need? : https://github.com/Azure/azure-notificationhubs-java-backend

Thanks


Replies (10)

RE: Send push notification with every message - Added by Wojciech Kapcia 7 months ago

Most likely you would want to develop:
  • a component which would handle communication with the Azure Notification Hubs;
  • a plugin which would forward relevant stanzas/messages do your component.

Please refer to Tigase Development Guide for the details how to go about developing those.

RE: Send push notification with every message - Added by S E 7 months ago

Is it necessary to use a component? Can it all be done simply by using a plugin?

Actually, our server already sends push notifications to offline users (but it is only using Apple Push Notifications). Unfortunately I never developed anything for the server before, and the previous developer is no longer at our company so I can't ask him for help.

Anyways, I ask if it is necessary because I used PSI's Service Discovery option, and the only components that are running on our server are MUC and PubSub, yet I am still able to receive push notifications on my iPhone. So, would this mean that the previous developer implemented push notifications by only using a plugin?

RE: Send push notification with every message - Added by Wojciech Kapcia 7 months ago

Staton Eichman wrote:

Is it necessary to use a component? Can it all be done simply by using a plugin?

It's possible to use a plugin, but dedicated component will definitely be a better solution.

Actually, our server already sends push notifications to offline users (but it is only using Apple Push Notifications). Unfortunately I never developed anything for the server before, and the previous developer is no longer at our company so I can't ask him for help.

We offer consulting services - please contact us directly http://tigase.net/contact :-)

Anyways, I ask if it is necessary because I used PSI's Service Discovery option, and the only components that are running on our server are MUC and PubSub, yet I am still able to receive push notifications on my iPhone. So, would this mean that the previous developer implemented push notifications by only using a plugin?

It's really difficult to comment on your installation with such scarce detail. It could be a component+plugin, it can be a plugin-only solution.

RE: Send push notification with every message - Added by S E 6 months ago

Assuming I just went with a plugin; What is the process of adding a plugin to the server? Is it as simple as editing the init.properties file, and then adding my .jar to the plugins folder (and then restart the server)?

RE: Send push notification with every message - Added by Wojciech Kapcia 6 months ago

Staton Eichman wrote:

Assuming I just went with a plugin; What is the process of adding a plugin to the server? Is it as simple as editing the init.properties file, and then adding my .jar to the plugins folder (and then restart the server)?

In a nutshell - yes: Plugin Configuration

RE: Send push notification with every message - Added by S E 6 months ago

Just to confirm, does the server need to be reset after adding the plugin?

RE: Send push notification with every message - Added by S E 6 months ago

I overwrote a .jar file on the server, restarted the server, and then the server would not start. So I reverted back to the original jar file, restarted the server again, and now the server works fine. But everytime I send a message, I get this error (it is supposed to send a push notification):

2017-03-27 18:58:13.740 [in_1-sess-man]    SessionManager.processPacket()     WARNING:  Error packet to the SM's own session: from=sess-man@db3, to=sess-man@db3, DATA=...

But its the exact same jar file as before, so why am I getting this warning now? Previously, it was working fine.

RE: Send push notification with every message - Added by S E 6 months ago

Here is the packet that is in question. It is using modified code from Kontalk's Push notifications, to work with APNS instead of GCM.

<pushmessage from="push@mydomain.net" type="error" to="mydomain.net">
    <message from="aaaaaa@mydomain.net/MatriX-for-Android" type="chat" xmlns="jabber:client" id="1490669155576" to="zzzzzz@mydomain.net">
        <body>d</body>
        <subject>chat</subject>
        <time>1490669155576</time>
        <request xmlns="urn:xmpp:receipts"/>
    </message>
    <error code="501" type="cancel">
        <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
        <text xml:lang="en" xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Feature not supported yet.</text>
    </error>
</pushmessage>, SIZE=548, XMLNS=null, PRIORITY=NORMAL, PERMISSION=NONE, TYPE=error

Again, it was working fine before I restarted the server. Do I need to restart it in a certain way? (Using Windows Server). I tried starting it from the Services manager, tried starting it by double clicking Run.bat, but still no success.

The plugin/component should be loaded, as I see this entry in the log file before the above entry:

MyAppPushNotification.postProcess()  FINEST: Processing packet: from=sess-man@db3, to=sess-man@db3, DATA=<pushmessage ...

Running Tigase-7.0.1-b3809

Edit: although the log file says the plugin loaded, using PSI's service discovery and logged in as admin, I do not see my component listed

RE: Send push notification with every message - Added by S E 6 months ago

After doing a bit more work and research, I still can't solve this issue. Here is the code that creates the "push" packet, that is to be processed by the push component:

public void postProcess(Packet packet, XMPPResourceConnection session, NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings) {

    if (session == null && packet.getElemName().equals(Message.ELEM_NAME) 
        && packet.getType() == StanzaType.chat 
        && (packet.getElement().getChild("body") != null 
            || packet.getElement().getChild("request", "urn:xmpp:receipts") != null)) {

        if (log.isLoggable(Level.FINEST)) {
            log.finest("Processing packet: " + packet.toString());
        }

        Element request = new Element("message");
        request.setAttribute("type", "push");

        request.addChild(new Element("push",
            new String[]{"xmlns", "jid"},
            new String[]{XMLNS, packet.getStanzaTo().getBareJID().toString()}));

        // send request to push component
        JID compJid = JID.jidInstanceNS(componentName, packet.getStanzaTo().getDomain(), null);
        JID fromJid = JID.jidInstanceNS(packet.getStanzaTo().getDomain());
        Packet p = Packet.packetInstance(request, fromJid, compJid);

        results.offer(p);
        packet.processedBy(ID);

    }
}

From the log file:

2017-03-29 16:27:34.496 [in_1-sess-man]    SessionManager.processPacket()     WARNING:  Error packet to the SM's own session: from=sess-man@db3, to=sess-man@db3, DATA=
<message to="mydomain.net" type="error" from="push@mydomain.net">
    <push jid="aaaaaaaa@mydomain.net" xmlns="http://mydomain.net/extensions/push"/>
    <error code="503" type="cancel">
        <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
        <text xml:lang="en" xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Service not available.</text>
    </error>
</message>
, SIZE=360, XMLNS=null, PRIORITY=NORMAL, PERMISSION=NONE, TYPE=error

Here is the function where the "Error packet to the SM's own session" is coming from: https://projects.tigase.org/projects/tigase-server/repository/revisions/master/entry/server/src/main/java/tigase/server/xmppsession/SessionManager.java#L1604

Any help would be greatly appreciated.

RE: Send push notification with every message - Added by Wojciech Kapcia 6 months ago

Staton Eichman wrote:

Just to confirm, does the server need to be reset after adding the plugin?

Yes, each time you change binary or configuration file you have to restart the server to apply the changes.

Staton Eichman wrote:

I overwrote a .jar file on the server, restarted the server, and then the server would not start. So I reverted back to the original jar file, restarted the server again, and now the server works fine. But everytime I send a message, I get this error (it is supposed to send a push notification):

[...]

But its the exact same jar file as before, so why am I getting this warning now? Previously, it was working fine.

Staton Eichman wrote:

Here is the packet that is in question. It is using modified code from Kontalk's Push notifications, to work with APNS instead of GCM.

[...]

    <error code="501" type="cancel">
        <feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
        <text xml:lang="en" xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Feature not supported yet.</text>
    </error>

This is an error packet from push component indicating that there is a problem with it (i.e. this is a response)

Again, it was working fine before I restarted the server. Do I need to restart it in a certain way? (Using Windows Server). I tried starting it from the Services manager, tried starting it by double clicking Run.bat, but still no success.

It's really difficult to troubleshoot it with so little information. Is your component deployed locally (i.e. within same server instance)? or is it external component? It looks it's internal (judging from the logs) but it's malfunctioning for some reason.

The plugin/component should be loaded, as I see this entry in the log file before the above entry:

[...]

Running Tigase-7.0.1-b3809

Edit: although the log file says the plugin loaded, using PSI's service discovery and logged in as admin, I do not see my component listed

You won't see pluing in service discovery. You will only see component if you are logged as an admin user.

Staton Eichman wrote:

After doing a bit more work and research, I still can't solve this issue. Here is the code that creates the "push" packet, that is to be processed by the push component:

[...]

From the log file:
[...]

Here is the function where the "Error packet to the SM's own session" is coming from: https://projects.tigase.org/projects/tigase-server/repository/revisions/master/entry/server/src/main/java/tigase/server/xmppsession/SessionManager.java#L1604

Any help would be greatly appreciated.

Check how does the generated packet looks like and if it's correctly addressed.

    (1-10/10)