Vous êtes sur la page 1sur 37

LIBRARY INFORMATION CHATBOT ON

MESSENGER PLATFORM

A project report submitted in partial fulfillment of the requirements for


B.Tech. Project

B.Tech.

by

Anni Gupta (2013IPG-22)


Rahul Yadav (2013IPG-87)
Prashant Kumar (2013IPG-81)

ABV INDIAN INSTITUTE OF INFORMATION


TECHNOLOGY AND MANAGEMENT
GWALIOR-474 010

2016
i

CANDIDATES DECLARATION

We hereby certify that the work, which is being presented in the report, entitled Li-
brary Information Chatbot on Messenger Platform, in partial fulfillment of the re-
quirement for the award of the Degree of Bachelor of Technology and submitted to
the institution is an authentic record of our own work carried out during the period May
2016 to October 2016 under the supervision of Dr. Vinay Singh . We also cited the
reference about the text(s)/figure(s)/table(s) from where they have been taken.

Date: Signatures of the Candidates

This is to certify that the above statement made by the candidates is correct to the best
of my knowledge.

Date: Signatures of the Research Supervisors


ii

ABSTRACT

This project aims to provide a way to avail library and its resources information readily
through a chatbot. The chatbot was developed on messenger platform using Facebook
for developers. It has SQL database to store the data pertaining to library. The open
source PHP program is used to communicate database to the user interface data. The
user interface are templates provided by messenger platform for developing messenger
chatbot. Sample data are crawled from various web pages. Users directly knew infor-
mation regarding library and its resources. It has eased the efforts students had to make
to get library information. It has been information on-the-go, you need it and you get
it instantly. Since the chatbot is made on messenger platform, it is readily available to
most of the students. It provides crucial information that students require. It lessens the
burden to login to ones account to get the information by being a handy solution to all
facebook connected users.

Keywords: Chatbot, Messenger Platform, Libraries, Library users, Library facili-


ties.
iii

ACKNOWLEDGEMENTS

We are highly indebted to Dr. Vinay Singh and are obliged for giving us the autonomy
of functioning and experimenting with ideas. We would like to take this opportunity to
express our profound gratitude to them not only for their academic guidance but also
for their personal interest in our project and constant support coupled with confidence
boosting and motivating sessions which proved very fruitful and were instrumental in
infusing self-assurance and trust within us. The nurturing and blossoming of the present
work is mainly due to their valuable guidance, suggestions, astute judgment, construc-
tive criticism and an eye for perfection. Our mentor always answered myriad of our
doubts with smiling graciousness and prodigious patience, never letting us feel that we
are novices by always lending an ear to our views, appreciating and improving them
and by giving us a free hand in our project. Its only because of their overwhelming
interest and helpful attitude, the present work has attained the stage it has.
Finally, we are grateful to our Institution and colleagues whose constant encouragement
served to renew our spirit, refocus our attention and energy and helped us in carrying
out this work.

(Anni Gupta) (Rahul Yadav) (Prashant Kumar)


TABLE OF CONTENTS

ABSTRACT ii

LIST OF TABLES v

LIST OF FIGURES v

1 INTRODUCTION AND LITERATURE SURVEY viii


1.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii
1.2 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii
1.3 Expected Outcomes . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1.4 Literature Review . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
1.5 Literature Gap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

2 DESIGN DETAILS AND IMPLEMENTATION x


2.1 Design Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x
2.1.1 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x
2.1.1.1 Data Extraction . . . . . . . . . . . . . . . . . . . . x
2.1.1.2 Data Processing . . . . . . . . . . . . . . . . . . . . xi
2.1.1.3 Interface Templates . . . . . . . . . . . . . . . . . . xiii
2.1.2 Database Architechture . . . . . . . . . . . . . . . . . . . . . . xviii
2.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
2.2.1 Connnection messenger bot and Node.js server(Troy et al., 2012)(Leon-
hardt et al., 2007) . . . . . . . . . . . . . . . . . . . . . . . . . xxi
2.2.2 A common facebook Api used in sending results of users query
and to the handle to each events like message ,attachments,postback,
and sending text message and templates to the chat bot user : . xxii
2.2.3 Track the users action what he is doing currently and respond
according to actions: . . . . . . . . . . . . . . . . . . . . . . . xxiii
2.2.4 Function to send relevant match results to chat bot user accord-
ing to his query: . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
2.2.5 Function to send chatbot user profile information : . . . . . . . xxiv

iv
TABLE OF CONTENTS v

2.2.6 Function to used in sending a generic template to the user: . . . xxv


2.2.7 Connection between node.js server and mongo.DB database
and register a user in database : . . . . . . . . . . . . . . . . . xxvi
2.3 Testing : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi

3 RESULTS AND DISCUSSION xxvii

4 CONCLUSION AND FUTURE WORK xxxiv


4.1 CONCLUSION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiv
4.2 FUTURE WORK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiv

REFERENCES xxxiv
LIST OF FIGURES

2.1 Greeting Text Template . . . . . . . . . . . . . . . . . . . . . . . . . . xiv


2.2 Generic Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
2.3 Text Message Template . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
2.4 Button Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
2.5 Facebookk User Database . . . . . . . . . . . . . . . . . . . . . . . . . xviii
2.6 Books Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
2.7 Libraray User Database . . . . . . . . . . . . . . . . . . . . . . . . . . xix
2.8 Code Snippet 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
2.9 Code Snippet 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
2.10 Code Snippet 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
2.11 Code Snippet 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
2.12 Code Snippet 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
2.14 Code Snippet 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
2.15 Code Snippet 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
2.16 Code Snippet 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
2.17 Code Snippet 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
2.18 Code Snippet 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
2.19 Code Snippet 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
2.20 Code Snippet 13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
2.21 Code Snippet 13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi
2.22 Code Snippett 14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi

3.1 Getting Started and Authentication. . . . . . . . . . . . . . . . . . . . xxvii


3.2 Verification of OTP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxviii
3.3 Book Search Options . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix
3.4 Results of book search. . . . . . . . . . . . . . . . . . . . . . . . . . . xxx
3.5 More results on book search. . . . . . . . . . . . . . . . . . . . . . . . xxxi
3.6 Persistent Menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxii
3.7 User Profile and About Us. . . . . . . . . . . . . . . . . . . . . . . . . xxxiii

vi
LIST OF FIGURES vii

ABBREVIATIONS

Mongo DB Mongo Database


JSON Javascript Object Notation
Node.js Node Javascript
PHP Hypertext Preprocessor
CHAPTER 1

INTRODUCTION AND
LITERATURE SURVEY

1.1 General
Today the world is all about smart users and smart services one provides. Every inch
of life moves with the existing technologies available in the world. Things have turned
out to be faster, smarter and easier. Social networking has become a part of ones life
and students thrive on it. Every month, over 900 million people around the world com-
municate with friends, families and businesses on Messenger(Facebook, 2016).People
are now spending more time in messaging apps than in social media and that is a huge
turning point. Messaging apps are the platforms of the future and bots will be how their
users access all sorts of services(Reading About Chatbot 1, n.d.).Now-a-days, these
messenger apps are providing platform to develop chatbots for anyone who wants to
reach out to people to solve their problems either by providing services or sugges-
tions(Readings About Chatbot 2., 2016)(Readings About Chatbot 3., 2016)(Readings
About Chatbot 4., 2016). Chatbots engage users with an automated interactive inter-
face which turn out to be interesting way of getting information.

1.2 Objective
Purpose of the project is to make library information readily available to one. It is to
put the use of social networking attachment of students to give them useful information
regarding library. It is to ease out the difficulties a student face while procuring the
information related to library and its resources. Integrating this library chatbot within
the messenger doesnt ask one to install anything. Its simple and easy to use with a
sequence of questions and answers.

viii
CHAPTER 1. INTRODUCTION AND LITERATURE SURVEY ix

1.3 Expected Outcomes


Students will find it handy and get information at the instant once they are registered
in the chatbot. Rather than just conversational chats, it has interactive interface with
graphical content which end users will find amusing. Since, bots in messenger has been
particularly used for commercial purposes, implementation of such chatbots would be
really different and interesting.

1.4 Literature Review


The idea to implement a chatbot on messenger platform to make library resources in-
formation handy was incurred due to popularity chatbot gained on messenger platform
based on various solutions to problems either a shopping bot or gym trainer. In (Face-
book, 2016), messenger chatbot was briefly described with all its components to have
an overall idea of what all one can do to use for solving problems with a huge audience
(Messenger Users). Efficient search in MongoDB uses three processes Stop Words,
Stemming and Scoring was studied under (Searching Technique in MongoDB., 2016).
In (Connection between server and database., 2016), Node.js and MongoDB connec-
tion was established to share the data stored in the database to user interface. It was
basically to communicate server made in Node.js with the database MongoDB. Face-
book for developers provides developers a complete guide to build bots on messenger
platform (Messenger Chatbot Documention., 2016). It also contains a sample code to
run for the first time to help developers learn what and how features can be imple-
mented. It is a thorough guide for the developers to begin with. All updates in features
provided on messenger platform is detailed under (Messenger Chatbot Documention.,
2016)(Chatbot Fb Page., n.d.)(McNeal and Newyear, 2013b).

1.5 Literature Gap


Currently the bots made on messenger platform are generally commercial based or
problem solutions. And we all know todays students are very fond of online social
networking and they spend most of their time in it and that gave us a thought that we
can provide students a very handy and interesting way to procure the information re-
garding library resources. No such project was initiated by anyone. Chatbot integrated
on facebook messenger for getting information is really cool and interesting and that
motivated us to work on the project.
CHAPTER 2

DESIGN DETAILS AND


IMPLEMENTATION

2.1 Design Details

2.1.1 Data
2.1.1.1 Data Extraction

Sample Data was extracted using open source tool Import.io which helps to crawl data
from web pages. Sample Data extracted consisted of book images, book details, au-
thor names and publishers. Random numbers were also generated using PHP scripting
language for indexing books to give identity to each. Around 10,000 books details was
procured as sample data from (Sample Data., 2016).
[
{
"_id": 1,
"bookname": "Fundamentals of Data Structures in C",
"author": "Sahni Horowitz",
"total": 48,
"available": 48,
"barcode": "YFLAN7334",
"library_index": "6.002",
"image_url":http:ecx.images-amazon.comimagesI51jaORoxq+L._AC_US160_.jpg",
"price": 244
}
]

x
CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xi

Extracted data sample in JSON format

2.1.1.2 Data Processing

Extracted sample data using web crawler had many false and irrelevant data. PHP
scripting language was used to remove these unwanted dataset. Desired dataset was
also generated using the language(Allison, 2012).

<?php
$Param = $_POST;
$json = file_get_contents(php://input);
$j = json_decode($json);
//var_dump($j);

$purpose=$j->purpose;
//echo $purpose;
//require("api.php");
if(empty($purpose))
{
echo "$"."purpose not set ";
die();
}

switch ($purpose)
{
case books_json:
header(Content-Type: application/json);
$i=0;
$response=array();
$x=(float)006.001;
foreach ($j->data as $books)
{
$id=$books->_num;
$bookname=$books->bookname[0];
$author=$books->author[0];
$book_img=$books->book_img[0];
$author=substr($author,3);

//generate price for books


if(isset( $books->price ) )
CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xii

{
$price=($books->price[0]);
if($price==Paperback or $price==Hardcover or $price==0.00)
{
$price=mt_rand(300,1000);
}
$price=(int)$price;
if($price<=100)
{
$price=mt_rand(300,1000);
}
}
else
{
$price=mt_rand(300,1000);
}

//generate barcode for books


$barcode=mt_rand(1000,9999);
$len=5;
$result = "";
$chars = "ABCDEFGHIJKLMNOPRSTUVWXYZ";
$charArray = str_split($chars);
for($j = 0; $j < $len; $j++)
{
$randItem = array_rand($charArray);
$result .= "".$charArray[$randItem];
}
//generate library index

if($x<=$x+999)
{
$x=$x+0.001;
}
else
{
$x-=0.999;
$x++;
}
CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xiii

$x=number_format($x,3);

//total_no_of_copies avialable in library


$available=mt_rand(20,70);
$total=$available;

$barcode=$result.(string)$barcode;
$response[$i][_id]=$id;
$response[$i][bookname]=$bookname;
$response[$i][author]=$author;
$response[$i][total]=$total;
$response[$i][available]=$available;
$response[$i][barcode]=$barcode;
$response[$i][library_index]=$x;
$response[$i][image_url]=$book_img;
$response[$i][price]=$price;

$i++;
// break;
}
echo json_encode($response,JSON_PRETTY_PRINT);

$fp = fopen(results.json, w);


fwrite($fp, json_encode($response,JSON_PRETTY_PRINT));
fclose($fp);
break;
}
?>

Processing Code Using PHP scripting language

2.1.1.3 Interface Templates

Greeting Text Template:Greeting Text Template: Messenger Platform provides this


template to greet the user when user comes for the first the time on the bot (Fb Chatbot
Greeting Template., 2016).
CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xiv

Figure 2.1: Greeting Text Template


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xv

Generic Template It is a horizontal scrollable template consisting image attach-


ment, short description and button (Fb Chatbot Generic Template., n.d.).

Figure 2.2: Generic Template


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xvi

Text Message Template: This features how a developer can send plain text mes-
sages using API provided by facebook for developers (Fb Chatbot Text Template.,
2016).

Figure 2.3: Text Message Template


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xvii

Button Template: This takes inputs of the user through button click (Fb Chatbot
Button Template., 2016).

Figure 2.4: Button Template


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xviii

2.1.2 Database Architechture


This describes how data schema has been designed for the chatbot to converse. Code
and figures are attached below. Data is in JSON format(McNeal and Newyear, 2013a)(Yu,
2015).
var mongoose = require(mongoose);
var Schema = mongoose.Schema;

// create a schema
var userSchema = new Schema({
facebookId:{ type: String,unique: true },
currentNode:Number,
first_name: String,
last_name:String,
roll_number:String,
otp_number:String,
gender:String,
admin:Number
});

// the schema is useless so far


// we need to create a model using it
var User = mongoose.model(User, userSchema);
//connect with database
mongoose.connect(mongodb://localhost:27017/LibraryBot);
// make this available to our users in our Node applications
module.exports = User;

Figure 2.5: Facebookk User Database


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xix

Figure 2.6: Books Database

Figure 2.7: Libraray User Database


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xx

2.2 Implementation

Greeting Text

Enter Roll No

Send OTP On
Webmail

False Verify True


OTP

Enter OTP Again


Next Action

View Profile Search Book

Send Profile
Details Search
By

Book Search by Author


Name Both Name

Input For
Search Query

Top Two Results

More Result

Figure 2.8: Code Snippet 1


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xxi

2.2.1 Connnection messenger bot and Node.js server(Troy et al.,


2012)(Leonhardt et al., 2007)

Figure 2.9: Code Snippet 1

Figure 2.10: Code Snippet 2


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xxii

2.2.2 A common facebook Api used in sending results of users


query and to the handle to each events like message ,attach-
ments,postback, and sending text message and templates to
the chat bot user :

Figure 2.11: Code Snippet 3

Figure 2.12: Code Snippet 4


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xxiii

2.2.3 Track the users action what he is doing currently and respond
according to actions:

Figure 2.14: Code Snippet 6

2.2.4 Function to send relevant match results to chat bot user ac-
cording to his query:

Figure 2.15: Code Snippet 7

Figure 2.16: Code Snippet 8


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xxiv

2.2.5 Function to send chatbot user profile information :

Figure 2.17: Code Snippet 9

Figure 2.18: Code Snippet 10


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xxv

2.2.6 Function to used in sending a generic template to the user:

Figure 2.19: Code Snippet 11

Figure 2.20: Code Snippet 13


CHAPTER 2. DESIGN DETAILS AND IMPLEMENTATION xxvi

2.2.7 Connection between node.js server and mongo.DB database


and register a user in database :

Figure 2.21: Code Snippet 13

Figure 2.22: Code Snippett 14

2.3 Testing :
User make requests to chatbot and responses are given by the Node.js server using
MongoDB in a chat session. Server also tracks users current actions.
CHAPTER 3

RESULTS AND DISCUSSION

Responses to users requests are delivered to the users using facebook APIs. Initially,
a user needs to get authenticated to get started with the chatbot. Once, the user is
verified using OTP verification, user is allowed to avail the features of chatbot. A
persistent menu is always present to provide users shortcuts to directly get started with
the features.

Figure 3.1: Getting Started and Authentication.

xxvii
CHAPTER 3. RESULTS AND DISCUSSION xxviii

Figure 3.2: Verification of OTP.


CHAPTER 3. RESULTS AND DISCUSSION xxix

Figure 3.3: Book Search Options


CHAPTER 3. RESULTS AND DISCUSSION xxx

Figure 3.4: Results of book search.


CHAPTER 3. RESULTS AND DISCUSSION xxxi

Figure 3.5: More results on book search.


CHAPTER 3. RESULTS AND DISCUSSION xxxii

Figure 3.6: Persistent Menu.


CHAPTER 3. RESULTS AND DISCUSSION xxxiii

Figure 3.7: User Profile and About Us.


CHAPTER 4

CONCLUSION AND FUTURE


WORK

4.1 CONCLUSION
We implemented information based system on a chatbot efficiently which gives easier
availability of the information to the end users. The chatbot is integrated on the popular
Facebook messenger platform does not ask users to install any app, not asking any extra
space.

4.2 FUTURE WORK


This bot was mainly focussed on a college level library information system. But the big
picture can be seen as : Centralised Public Library System where people can directly
access any research related works, e-books, e-journals, e-thesis etc. It can be build
considering our library chatbot as building block of it. A similar platform like facebook
messenger platform can be developed and database can be stored on cloud servers.

xxxiv
REFERENCES

[1] Allison, D.: 2012, Chatbots in the library: is it time?, Library Hi Tech 30(1), 95
107.

[2] Chatbot Fb Page.: n.d.


URL: https://www.facebook.com/chatbotsmagazine/

[3] Connection between server and database.: 2016.


URL: https://scotch.io/tutorials/using-mongoosejs-in-node-js-and-mongodb-
applications

[4] Facebook: 2016, Messenger chatbot guidelines.


URL: https://developers.facebook.com/blog/post/2016/07/01/bots-for-messenger-
updates/

[5] Fb Chatbot Button Template.: 2016.


URL: https://developers.facebook.com/docs/messenger-platform/send-api-
reference/button-template?__mref=message_bubble

[6] Fb Chatbot Generic Template.: n.d.


URL: https://developers.facebook.com/docs/messenger-platform/send-api-
reference/generic-template?__mref=message_bubble

[7] Fb Chatbot Greeting Template.: 2016.


URL: https://developers.facebook.com/docs/messenger-platform/thread-
settings/greeting-text?__mref=message_bubble

[8] Fb Chatbot Text Template.: 2016.


URL: https://developers.facebook.com/docs/messenger-platform/send-api-
reference/text-message?__mref=message_bubble

[9] Leonhardt, M. D., Tarouco, L., Vicari, R. M., Santos, E. R. and da Silva, M.
d. S.: 2007, Using chatbots for network management training through problem-
based oriented education, Seventh IEEE International Conference on Advanced
Learning Technologies (ICALT 2007), IEEE, pp. 845847.

xxxv
REFERENCES xxxvi

[10] McNeal, M. L. and Newyear, D.: 2013a, Introducing chatbots in libraries, Library
Technology Reports 49(8), 510.

[11] McNeal, M. and Newyear, D.: 2013b, Chatbots: Automating reference in public
libraries, Robots in Academic Libraries: Advancements in Library Automation:
Advancements in Library Automation p. 101.

[12] Messenger Chatbot Documention.: 2016.


URL: https://developers.facebook.com/docs/messenger-platform

[13] Reading About Chatbot 1: n.d.


URL: https://chatbotsmagazine.com/the-complete-beginner-s-guide-to-chatbots-
8280b7b906ca.eyetiia8d

[14] Readings About Chatbot 2.: 2016.


URL: https://www.facebook.com/notes/lemmings-io/facebook-messenger-is-
competing-directly-with-android-and-ios/1747424302184701

[15] Readings About Chatbot 3.: 2016.


URL: https://chatbotsmagazine.com/building-your-chatbots-existing-solutions-
and-opportunities-873c5dc66d48.non9qvh7z

[16] Readings About Chatbot 4.: 2016.


URL: https://chatbotsmagazine.com/the-7-things-everyone-needs-to-know-about-
chatbots-1f8e883210e9.vce3uydiv

[17] Sample Data.: 2016.


URL: http://www.delhibookstore.com/

[18] Searching Technique in MongoDB.: 2016.


URL: https://code.tutsplus.com/tutorials/full-text-search-in-mongodbcms-24835

[19] Troy, R. et al.: 2012, Designing an embodied conversational agent for a self-
access center, lA
d aTl
C
T Z u 23, 171182.

[20] Yu, J.: 2015, A personalized chat-bot based on facebook update.

Vous aimerez peut-être aussi