Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Anastasis Ksenos #1
Member since Apr 2022 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Matrix XMMP - How to retrieve stanza from archived messages.
Hello,

We are using OpenFire version 4.7.1 with the Monitoring Service installed. Following the code which I found here :https://forum.ag-software.net/thread/2140-YAMAQ-Yet-anothe… I have managed to retrieve archived messages body, however we have many scenarios which message body is not enough. We want to retrieve MessageArchive stanza as well. By executing the above query at the server database we find out that message stanza is stored at the data table but is there a way to retrieve it using matrix xmpp ? Any help would be appreciated.

SELECT TOP (1000) [messageID]
      ,[conversationID]
      ,[fromJID]
      ,[fromJIDResource]
      ,[toJID]
      ,[toJIDResource]
      ,[sentDate]
      ,[stanza]
      ,[body]
      ,[isPMforJID]
  FROM [OpenFire].[dbo].[ofMessageArchive]
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello Anastasis,

I think what you are looking for is the following extension:
XEP-0313: Message Archive Management

Can you study the extension and let me know if this is what you are looking for?
When you have problems building the packets from the extension with MatriX then please let me know.

Alex
Anastasis Ksenos #3
Member since Apr 2022 · 3 posts
Group memberships: Members
Show profile · Link to this post
Hello Alex,

Thank you for the quick response. I studied the extension but I am not sure how to implement it. Let my share my code

  1.    public void RetrieveArchivedMessages(string with)
  2.         {
  3.             var query = new Matrix.Xmpp.MessageArchiving.List()
  4.             {
  5.                 With = new Matrix.Jid(with),
  6.                 ResultSet = new Matrix.Xmpp.ResultSetManagement.Set()
  7.             };
  8.  
  9.             var request = new Matrix.Xmpp.Client.Iq
  10.             {
  11.                 Type = Matrix.Xmpp.IqType.Get,
  12.                 Query = query
  13.             };
  14.  
  15.             request.GenerateId();
  16.  
  17.             this.Client.IqFilter.SendIq(request, RetrieveSessionsListCallback);
  18.         }
  19.  
  20.         private void RetrieveSessionsListCallback(object sender, IqEventArgs e)
  21.         {
  22.             if (e.Iq.Type != Matrix.Xmpp.IqType.Result)
  23.                 return;
  24.  
  25.             var sessions = e.Iq.Element<Matrix.Xmpp.MessageArchiving.List>();
  26.             if (sessions == null || sessions.Elements<Matrix.Xmpp.MessageArchiving.Chat>().Count() == 0)
  27.                 return;
  28.  
  29.             foreach (var session in sessions.Elements<Matrix.Xmpp.MessageArchiving.Chat>())
  30.                 RetrieveChatSession(session);
  31.         }
  32.  
  33.         private void RetrieveChatSession(Matrix.Xmpp.MessageArchiving.Chat session)
  34.         {
  35.             if (session == null)
  36.                 return;
  37.  
  38.             var query = new Matrix.Xmpp.MessageArchiving.Retrieve()
  39.             {
  40.                 With = session.With,
  41.                 Start = session.Start,
  42.                 ResultSet = new Matrix.Xmpp.ResultSetManagement.Set { Maximum = 100 },
  43.             };
  44.  
  45.             var request = new Matrix.Xmpp.Client.Iq()
  46.             {
  47.                 Type = Matrix.Xmpp.IqType.Get,
  48.                 Query = query
  49.             };
  50.  
  51.             request.GenerateId();
  52.  
  53.             this.Client.IqFilter.SendIq(request, RetrieveSessionMessagesCallback);
  54.         }
  55.  
  56.         private void RetrieveSessionMessagesCallback(object sender, IqEventArgs e)
  57.         {
  58.             if (e.Iq.Type != Matrix.Xmpp.IqType.Result)
  59.                 return;
  60.  
  61.             var chat = e.Iq.Element<Matrix.Xmpp.MessageArchiving.Chat>();
  62.             if (chat == null)
  63.                 return;
  64.  
  65.             var items = chat.GetItems();
  66.             if (items == null)
  67.                 return;
  68.  
  69.             var start = chat.Start;
  70.             var list = new System.Collections.Generic.List<String>();
  71.  
  72.             foreach (Matrix.Xmpp.MessageArchiving.MessageItem message in items)
  73.             {
  74.                 AddMessage(message, start, list);
  75.             }
  76.         }
  77.  
  78.         private void AddMessage(Matrix.Xmpp.MessageArchiving.MessageItem message, DateTime startTime, System.Collections.Generic.List<String> list)
  79.         {
  80.             if (message == null)
  81.                 return;
  82.  
  83.             var from = message.Jid?.Bare ?? "me";
  84.             list.Add(message.Body + message.TimeStamp.ToString());
  85.         }

The Matrix.Xmpp.MessageArchiving.MessageItem class does not contain a stanza property.

I get the following response which does not contain the message stanza property. As I mentioned in my previous post the server does store the message stanza at the ofMessageArchive table but how we can retrieve it ?

  1. <iq type="result" id="MX_5" from="esmaster@ast-pc.soft.gr" to="esmaster@ast-pc.soft.gr/AST-PC/9788" xmlns="jabber:client">
  2.  <chat xmlns="urn:xmpp:archive" with="esdev@ast-pc.soft.gr" start="2022-04-13T11:57:58.855Z">
  3.     <to secs="0" jid="esdev@ast-pc.soft.gr">
  4.       <body>hello</body>
  5.     </to>
  6.     <to secs="4" jid="esdev@ast-pc.soft.gr">
  7.       <body>test archive</body>
  8.     </to>
  9.     <to secs="20" jid="esdev@ast-pc.soft.gr">
  10.       <body>???? ????????</body>
  11.     </to>
  12.     <to secs="17" jid="esdev@ast-pc.soft.gr">
  13.       <body>???? ????????.xlsx</body>
  14.     </to>
  15.     <set xmlns="http://jabber.org/protocol/rsm">
  16.       <first index="0">0</first>
  17.       <last>3</last>
  18.       <count>4</count>
  19.     </set>
  20.  </chat>
  21. </iq>
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello Anastasis,

it looks to me like you are using the older and deprecated extension:
XEP-0136: Message Archiving

But I was suggesting to use:
XEP-0313: Message Archive Management

And see there in example 17 how the server would send you the original message under the <forwarded/> tag:
https://xmpp.org/extensions/xep-0313.html#results

Alex
Anastasis Ksenos #5
Member since Apr 2022 · 3 posts
Group memberships: Members
Show profile · Link to this post
Yes you were right. Using the XEP-0313 I have managed to retrieve it. Thank you for your help.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: