Open Facebook Messenger | Open Chat Window | Send Message using Lightning Component Salesforce


Hello folks,

In this blog you will learn to open Facebook Messenger from our Salesforce org. Then we will send message using the facebook messenger to the particular contact using their facebook username.

To store the username I have created a new custom field in my Contact object. The field api is fb_username__c

Please follow the code below : 

Component
1
2
3
4
5
<aura:component controller="Vlog_facebookCTRL" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
	<aura:attribute name="recordId" type="String" />
    <aura:attribute name="con" type="Contact" />
    <aura:handler name="init" action="{!c.doInit}" value="{!this}" />
</aura:component>


Controller.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
({
    doInit : function(component, event, helper) {
        var action = component.get("c.fetchContact");
        action.setParams({
            "conId" : component.get("v.recordId").toString()
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            var data;
            if(state === 'SUCCESS'){
                var result = response.getReturnValue();
                component.set("v.con", result);
                
                var contact = component.get("v.con");
                var url= "https://m.me/"+contact.FB_Username__c;
                window.open(url, '_blank');
                $A.get("e.force:closeQuickAction").fire();
            }
        });
        $A.enqueueAction(action);
        
        
    }
})


Apex Controller
1
2
3
4
5
6
7
public class Vlog_facebookCTRL {
	@AuraEnabled 
    public static Contact fetchContact(String conId){
        return [Select Id, FB_Username__c FROM Contact where Id=:conId ];
    }
    
}

Add the component as a quick action on contact to open the chat window for the particular contact.

Checkout the vlog also !


If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Keep Coding 

Post a Comment

0 Comments