Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HistoricalMessaging not working in agora-react-native-rtm": "^1.2.2-alpha.3" Version #35

Open
kuldipp1995 opened this issue Apr 8, 2021 · 5 comments

Comments

@kuldipp1995
Copy link

kuldipp1995 commented Apr 8, 2021

I have added below code but now works for me, I when I'm try to get recent chat list then not getting any messages

Message History EndPoint:-
"https://api.agora.io/dev/v2/project/{{appId}}/rtm/message/history/query"

import RtmEngine from 'agora-react-native-rtm';

const APP_ID = ''
let engine;

import { EventRegister } from 'react-native-event-listeners'

class AgoraManager {

static loginUserUid = ''

static agoraInit = async(strEmail, strChatToken) => {
    
    arrChatMessages = []

    engine = new RtmEngine();
    loginUserUid = strEmail
    
    engine.on('error', evt => {
        console.log(evt);
    });

    //4.Received Observer
    engine.on('messageReceived', evt => { 
        let {text, ts, peerId} = evt;
        let dictMessage = { user_id: peerId, message: text, msgTimeStamp: ts}
        console.log("Message recievied =>", dictMessage);
        EventRegister.emit('RECEIVE_NEW_MESSAGE', dictMessage)
    });

    //1. Create Client
    await engine.createClient(APP_ID).catch(e => console.log(e));
    
    //2. Login in agora
    await engine.login({uid: loginUserUid, token: strChatToken})

}

static sendMessage = async (dictAgoraPeerMessage) => {
    await engine.sendMessageToPeer(dictAgoraPeerMessage).then((data) => {
        console.log("Send Message With Response =>",data)
    }).catch((err) => {
        console.log("Message Error =>",error)
    })
}

static endChat = async () => {
    await engine.logout().catch(e => console.log(e));
    await engine.destroyClient().catch(e => console.log(e));
};

}

export { AgoraManager };

Chat.js
let dictMessage = { 'peerId': this.state.strReceiveUId, 'offline': true, 'text': this.state.strUserMessage.trim(),
const {response} = await AgoraManager.sendMessage(dictMessage)

AgoraRTM.m

// sendMessageToPeer
RCT_EXPORT_METHOD(sendMessageToPeer:
(NSDictionary *) params
resolve:
(RCTPromiseResolveBlock) resolve
reject:
(RCTPromiseRejectBlock) reject) {
BOOL offline = [params[@"offline"] boolValue];
NSString *text = params[@"text"];
NSString *peerId = params[@"peerId"];

AgoraRtmSendMessageOptions *options = [AgoraRtmSendMessageOptions new];
**[options setEnableHistoricalMessaging:true];**
[options setEnableOfflineMessaging:offline];
AgoraRtmMessage *message = [[AgoraRtmMessage new] initWithText:text];
[[self rtmKit] sendMessage:message toPeer:peerId sendMessageOptions:options completion:^(AgoraRtmSendPeerMessageErrorCode errorCode) {
    if (errorCode == AgoraRtmSendPeerMessageErrorOk) {
        resolve(nil);
    } else {
        reject(@(errorCode).stringValue, @"", nil);
    }
}];

}

Please suggest me any solution for this.

Thank you

@plutoless
Copy link
Collaborator

could you pls provide a full cURL copy of your request?

@RoJoHub
Copy link

RoJoHub commented Apr 8, 2021

Maybe you should be add listener after engine created?

@kuldipp1995
Copy link
Author

kuldipp1995 commented Apr 8, 2021

could you pls provide a full cURL copy of your request?

https://api.agora.io/dev/v2/project/7fbb032d23784374b7f38163102019ab/rtm/message/history/query

x-agora-token:- 0067fbb032d23784374b7f38163102019abIACP6+OdB7i4TwZq3HjQHJgNoycsH5Acbd1nRc7LIlCMQnmz7I4AAAAAEACNyCbp4fRvYAEA6AMAAAAA

uid:- zbruno@imaginovation.net

@kuldipp1995
Copy link
Author

kuldipp1995 commented Apr 12, 2021

Maybe you should be add listener after engine created?

Yes, we have moved our code as per your suggestion and try the same steps but history messages aren't displaying. Please provide the example link or something of react-native in which Historical Message display.

static agoraInit = async(strEmail, strChatToken) => {

    engine = new RtmEngine();
    loginUserUid = strEmail
    
    engine.on('error', evt => {
        console.log(evt);
    });

    //1. Create Client
    await engine.createClient(APP_ID).catch(e => console.log(e));
    
    //2. Login in agora
    await engine.login({uid: loginUserUid, token: strChatToken})

    //4.Received Observer
    engine.on('messageReceived', evt => { 
        let {text, ts, peerId} = evt;
        let dictMessage = { user_id: peerId, message: text, msgTimeStamp: ts}
        console.log("Message recievied =>", dictMessage);  
        EventRegister.emit('RECEIVE_NEW_MESSAGE', dictMessage)
    });
}

@rehmanalikwanso
Copy link

@kuldipp1995 If you got any solution about get messgae history then kindly share with me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants