Category: Chatbot

Salesforce Slack Integration


In this blog, I am going to explain how to set up chatbot with salesforce and Slack. Nowadays Chatbots are gaining more and more popularity thorough conducts a conversation via auditory or textual methods.we will build chat bot for Slack using Botkit — a popular and open source bot development kit written in node.js jsforce for Salesforce integration with node.js. 

Create a bot in Slack

Login you Slack account and go to bot configurations page, enter “any name you want ” in the username field and click Add Bot Integration.

you will be brought to an edit configuration page. Under Integration Settings section, there is an API Token which we will use it for later in the code for authentication.

Setup configuration

we are built on node js you can do it by npm init and npm install packages. but here is the package.JSON file which you can use.

Run the following command

Create a new file index.js in root directory and add the following code

Now go to your slack channel and type help to start interacting with the bot  as shown below. As of now, the code is working to fetch contact details to slack but you can extend to other levels.

Understand the Botkit

Before we make it be a real chatbot, let’s dive into the code and see how Botkit works.  Open the index.js file and you will see a lot of controller.hears() functions. In fact, hears() is a function provided by Botkit to listen messaging events based on matching keywords in message text and those are help and Salesforce

Here’s a simple example of hears() function;

I’ve added indirect_mention,direct_message,interactive_message_callback this parameter so this function can be fired when I say “@salesforce “ in the channel
Here’s the full list of parameter options from Botkit github:

Event Description
message_received This event is fired for any message of any kind that is received and can be used as a catch-all
ambient Ambient messages are messages that the bot can hear in a channel, but that does not mention the bot in any way
direct_mention Direct mentions are messages that begin with the bot’s name, as in “@bot hello”
mention Mentions are messages that contain the bot’s name, but not at the beginning, as in “hello @bot”
direct_message Direct messages are sent via private 1:1 direct message channels

The third parameter is a callback receiving bot and message 
the bot can be used to reply the received message using the functionreply (message, 'response text').

Apart from that, bot holds functions and data of slackbot and joined channels.

You can find the code here

Salesforce Skype Bot


In this blog, I am going to explain the step by step how to set up a skype bot with salesforce by using node js,jsforce, and botbuilder.

Setup Node Js Project

1. Create an empty folder to start the node js project.
2. Create a new package.json file and paste the below code into the package.json file 

3. Run npm install from the command promote to load all the node modules from the package.json
4.Now create a new file and name it as app.js and paste this code into app.js file.


5.Change appId & appPassword with your own appId and appPassword for chatbot and Salesforce username and password to get data from the salesforce.To get App Id and password follow below steps.

6.First login into your Microsoft account.

7.Goto this link: Click Here and complete sign in process 

8.Click on Register a bot and create a new bot.

9.Click create  button to register your bot Register an existing bot built using Bot Builder SDK

10.Now fill in your required details, select your bot image as shown below

11.Click on Create Microsoft App ID and password and then click on generate app Password to continue 

12.Now You got your App ID and Password and update them in code.

13.Now you need to add https messaging endpoint to listen for requests.

14.You can create one for free that will run locally on your system using the tool called ngrok and Download ngrok from here  Click Here .You will get a zip file, Extract that zip file into any folder and then open the file named ngrok.exe

15.Type and enter : ngrok http 8080

16.Now copy the https address from the command line of ngrok. Make sure you don’t close the ngrok after creating address cause then the endpoint address will not listen to any request.

17.Now paste this address into endpoint field and add api/messages” in the end as shown below on Bot Registration configuration sections.


18.Click on the register and save the bot.
19.Now go back to command prompt and type ‘ node app.js ‘ to start your node js application.
20.After the application starts you can test from the test section on the application.

Then type /help to start the bot conversion as shown below.

As shown in the above image you can post to chatter from the skype chatbot. once you test your application you can push the skype and use it.

Understand the Code

You can register the bot chat connect from the below code and it is going to Create chat connector for communicating with the Bot Framework Service

And most important think how we are going to establish the conversation as the communication between a bot and a user through one or more dialogs. A dialog, at its most basic level, is a reusable module that performs an operation or collects information from a user. the below code shows how to start the dialog

You can refer more details on dialogs  below links