Skip to content

Instantly share code, notes, and snippets.

@YuriFontella
Last active January 10, 2022 19:18
Show Gist options
  • Save YuriFontella/7d2516c9d3a3bad75e9f03de2b5bedc7 to your computer and use it in GitHub Desktop.
Save YuriFontella/7d2516c9d3a3bad75e9f03de2b5bedc7 to your computer and use it in GitHub Desktop.
//EMBEDD THE FRESHDESK MESSAGING MESSENGER CODE ON YOUR WEBSITE
// Start talking to your website visitors by embedding this code on your website. Remember, nothing will work until you do.
// Add the following script to your website's HTML source code before the end of the BODY tag. Add the script to each page where you want the messenger to appear. For setup instructions, see the
// Docs - https://freshchat.readthedocs.io/en/latest/intro.html
<script>
function initFreshChat() {
window.fcWidget.init({
token: '',
host: ''
});
}
function initialize(i,t){var e;i.getElementById(t)?initFreshChat():((e=i.createElement("script")).id=t,e.async=!0,e.src="https://wchat.freshchat.com/js/widget.js",e.onload=initFreshChat,i.head.appendChild(e))}function initiateCall(){initialize(document,"Freshdesk Messaging-js-sdk")}window.addEventListener?window.addEventListener("load",initiateCall,!1):window.attachEvent("load",initiateCall,!1);
</script>
// (Optional) Identify the user
// Copy the below lines under window.fcWidget.init inside initFreshChat function in the above snippet
// To set unique user id in your system when it is available
window.fcWidget.setExternalId("john.doe1987");
// To set user name
window.fcWidget.user.setFirstName("John");
// To set user email
window.fcWidget.user.setEmail("john.doe@gmail.com");
// To set user properties
window.fcWidget.user.setProperties({
plan: "Pro", // meta property 1
status: "Active" // meta property 2
});
// ZENVIA - API - SMS
// DOCS - https://zenvia.github.io/zenvia-openapi-spec/v2/#section/SMS-sender-and-recipient
const { post } = require('request-promise');
post({
uri: 'https://api.zenvia.com/v2/channels/sms/messages',
headers: {
'X-API-TOKEN': 'YOUR_API_TOKEN'
},
body: {
from: 'sender-identifier',
to: 'recipient-identifier',
contents: [{
type: 'text',
text: 'Some text message'
}]
},
json: true
})
.then((response) => {
console.log('Response:', response);
})
.catch((error) => {
console.log('Error:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment