Skip to content

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

Open
@kuldipp1995

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions