Intercom integration with Discourse?

AI-generated summary

Rob_Jeffrey is seeking help with integrating Intercom on their Discourse site, specifically to auto-populate the email address of logged-in users. dax suggests using a script that retrieves the user’s email from the Discourse API. The script sets up the Intercom settings with the user’s email, name, and other details. vinothkannans points out the official Intercom plugin topic, which Rob_Jeffrey finds helpful. Additionally, dax mentions a recently released theme component for Intercom, which can be found in a separate topic.

Hello all,

I have Intercom (https://www.intercom.com/) on my discourse site and I want to auto populate the email address as the user is already logged in with their email to the discouse forum (as its a closed community)

Intercom offer the following code in Ruby:

I’m guessing I cant use any server side code within the admin/customization panel in discourse its self but I am wondering if any one else has solved this problem before?

Thanks in advance, I really appreciate all responses.

Rob

Look at the howto topics about developing themes.

Hi Rob, I think you can do it if you add variables to the script, for example:

<script>
$.getJSON("/session/current.json", function(json) {
    var userusername = String(json.current_user.username);
    var currentname = String(json.current_user.name);
    var pathtojson = "/users/" + userusername + ".json";
    $.getJSON(pathtojson, function(json){
        var useremail = String(json.user.email);
        var createdatuser = String(json.user.created_at);

        window.intercomSettings = {
            app_id: '[APP_ID]',
            email: useremail,
            name: currentname,
            created_at: createdatuser,
            "discourse_username": userusername,
        };
    });
});
</script>

@Rob_Jeffrey have a look at our official Intercom plugin topic

Thanks for your reply! This worked great, genius

Ah great to know, in future discourse installs I will use the official plugin

We have also released some days ago a theme component for Intercom, you can take a look here