tinycreative / react-native-intercom

React Native wrapper for Intercom.io
MIT License
406 stars 280 forks source link

Add additional parameter in displayMessageComposerWithInitialMessage or a new method to force-send initial message #396

Closed smlarkin closed 2 years ago

smlarkin commented 3 years ago

The composition of the message is only half way there because, often times, a user does not "get" they should click "send" the exact message written for them once they are launched to Intercom. Receiving the predefined message is important for CS that use Intercom to guide them to exact next steps. Therefor...

It would be ideal to add an additional param or a new method so one Intercom is launched a message is sent on behalf of the user.

displayMessageComposerWithInitialMessage(message: string, send=false){
  // ...
}

...OR...

sendInitialMessageInComposer(message: string){
  // ...
}
Br1an-Boyle commented 3 years ago

@smlarkin 👋 This plugin will be unable to do what you'd like as the Intercom SDK API doesn't provide for this. The Intercom SDK has no plans to add this additional functionality at this time.

smlarkin commented 3 years ago

Hi there @bboyle18 :)

From my own experimentation, I have if your app access token on Intercom has the right permissions, you can follow these steps to create a new conversation on behalf of the user:

  1. Query the Intercom id of that user at this route: POST https://api.intercom.io/contacts/search ... {"query": { "field": "email","operator": "=","value": "test@me.com" } }
  2. Create a conversation o Intercom at this route: POST https://api.intercom.io/conversations ... { "from": { "type": "user", "id": "5f5bc135...." }, "body": "Can you help me do X..." }

Since you get the conversation ID back, you could launch Intercom into this conversation from a string of promise resolutions.

I did this all with fetch in a callback in React Native and it worked. But I am fairly naive to the native modules on Intercom and what can be done so I don't know how it would work using the current SDK.

Br1an-Boyle commented 3 years ago

Yes it's certainly possible to do using the Intercom REST API. Not sure whether this would be suitable to do with this plugin.

What you've done yourself seems to work well and is the best way of doing what you want to do 👍🏻