infobip / mobile-messaging-react-native-plugin

Mobile Messaging SDK plugin for React Native projects
24 stars 4 forks source link

TypeError: Cannot read property 'deleteAll' of undefined #43

Closed vokecodes closed 2 years ago

vokecodes commented 2 years ago

Below code results in a promise rejection with the error TypeError: Cannot read property 'deleteAll' of undefined

import { mobileMessaging } from 'infobip-mobile-messaging-react-native-plugin';
mobileMessaging.defaultMessageStorage().deleteAll(() => {
       console.log('Deleted all messages');
 });
vokecodes commented 2 years ago

I added this line of code to the initialization defaultMessageStorage: true. I didn't get the error but messages didn't get deleted.

riskpp commented 2 years ago

Hi @vokecodes, I suppose plugin version you are using is 5.0.1? Could you may be share logs and which platform are you testing?

vokecodes commented 2 years ago

@riskpp Yes, 5.0.1. Testing on Android. Shared logs via mail.

riskpp commented 2 years ago

Hi @vokecodes, from my side everything looks fine. You can check may be you've missed something from the Default message storage doc.

I've just implemented following in Example app Don't forget to add defaultMessageStorage: true to the config.

//components/homeScreen.js
//Implemented methods for default storage
class HomeScreen extends React.Component {
...
  deleteAll() {
    mobileMessaging.defaultMessageStorage().deleteAll(() => {
      console.log('Delete all');
    });
  }

  findAll() {
    mobileMessaging.defaultMessageStorage().findAll((messages) => {
      console.log('Find All, Messages: ' + JSON.stringify(messages));
    });
  }
 }
 ...
 //Added buttons to the home screen
 render() {
    return (
      <View style={styles.infoView}>
      ...
        <Button
            title="Delete All on default storage"
            onPress={() => this.deleteAll()}
        />
        <Button
            title="Find all messages from default storage"
            onPress={() => this.findAll()}
        />
      </View>
    );
}

Resulting logs:

 LOG  Event: ["messageReceived",{"body":"Text1","title":"Title1"}]
 LOG  Event: ["messageReceived",{"body":"Text2", "title":"Title2"}]
 LOG  Find All, Messages: [{"body":"Text1","title":"Title1"},{"body":"Text2","title":"Title2"}]
 LOG  Delete all
 LOG  Find All, Messages: []
vokecodes commented 2 years ago

Hi @riskpp , thanks. I made use of the Personalize API and that works well.

When I use mobileMessaging.personalize({userIdentity}), returns below error

Invalid phone number: 27999999913 (number does not have valid country/network prefix)

This is the user object passed

const userIdentity = {
        firstName: customer.firstName,
        lastName: customer.lastName,
        phones: [`+${customer.phone1}`],
        emails: [customer.email],
        externalUserId: customer.externalUniqueId,
    };
riskpp commented 2 years ago

Check the format of the number it should correspond to https://en.wikipedia.org/wiki/E.164, more information also here

vokecodes commented 2 years ago

Yes, I formatted it Invalid phone number: 270999999913 (number does not have valid country/network prefix)

riskpp commented 2 years ago

Hi @vokecodes, could you check the number one more time, it doesn't look valid per these rules - https://en.wikipedia.org/wiki/E.164

vokecodes commented 2 years ago

I used a random test number but need to use a real phone number.