Skip to content

Instantly share code, notes, and snippets.

@dhaniksahni
Created September 6, 2019 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaniksahni/42747ab37fe6ae49038332d8cf2de792 to your computer and use it in GitHub Desktop.
Save dhaniksahni/42747ab37fe6ae49038332d8cf2de792 to your computer and use it in GitHub Desktop.
Send WhatsApp Message using Lightning Component
<aura:component controller="WhatsAppMessageService" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
<lightning:notificationsLibrary aura:id="notifLib"/>
<div class="row">
<lightning:input aura:id="mobileNumber" name="mobileNumber" label="Mobile Number" />
<lightning:input aura:id="message" name="message" label="Message" />
</div>
<div class="row">
<lightning:button variant="brand" label="Send Message" title="Send Message" onclick="{! c.handleClick }" />
</div>
</aura:component>
({
handleClick : function(component, event, helper) {
helper.sendMessage(component, event);
}
})
({
sendMessage : function(component, event) {
var isSigned = false;
var action = component.get("c.sendMessage");
action.setParams({
mobileno: component.find("mobileNumber").get("v.value"),
message: component.find("message").get("v.value")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.find('notifLib').showNotice({
"variant": "info",
"header": "Success!",
"message": "WhatsApp Message Sent"
});
} else {
component.find('notifLib').showNotice({
"variant": "error",
"header": "Something has gone wrong!",
"message": "Unfortunately, there was a problem while sending WhatsApp Message"
});
}
});
$A.enqueueAction(action);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment