Skip to content

Commit

Permalink
Merge pull request #29 from jekram/sania
Browse files Browse the repository at this point in the history
SESSIONS #19,LIVE CHAT #20
  • Loading branch information
saniasiddiqui authored Dec 5, 2017
2 parents 1332b67 + aaacfb0 commit 4bc4a53
Show file tree
Hide file tree
Showing 9 changed files with 392 additions and 72 deletions.
8 changes: 6 additions & 2 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ body
}
#header
{
margin-top : -10px;
top: 0px;
width : 100%;
background-color : #2b3643;
height : 50px;
padding : 5px;
position: fixed
}
#header h3
{
Expand Down Expand Up @@ -189,7 +190,7 @@ font-family: "Century Gothic"
text-align: center;
}
#main > #divCredential,#divInformation {
padding: 10px 25px 10px 25px;
padding: 30px 25px 10px 25px;
}
#main > #successMessage {
margin: 25px;
Expand All @@ -206,3 +207,6 @@ font-family: "Century Gothic"
padding: 20px;
opacity: 1;
}
#maincontent {
margin-top: 50px;
}
95 changes: 95 additions & 0 deletions routes/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var express = require('express')
var request = require('request')
var router = express.Router()
var headers
var session
var chats = []
/* GET users listing. */
router.get('/sessions', function (req, res, next) {
console.log(req.session.userId)
Expand Down Expand Up @@ -36,4 +38,97 @@ router.get('/sessions', function (req, res, next) {
request.post(options, callback)
})

router.get('/sessions/:id', function (req, res, next) {
console.log(req.session.userId)
var id = req.params.id
headers = {
'app_id': req.session.kiboappid,
'app_secret': req.session.kiboappsecret,
'content-type': 'application/json'
}
var options = {
url: `https://staging.kibopush.com/api/sessions/${id}`,
headers: headers,
rejectUnauthorized: false
}

function callback (error, response, body) {
console.log('Response-Body', response.body)
if (!error && response.statusCode === 200) {
console.log('Response-Parse', JSON.parse(response.body))
var info = JSON.parse(response.body)
session = info.payload
chats = session.chats
console.log(session)
res.render('sessionDetails', { title: 'Sessions Details', session: session, chats: chats })
} else {
error = JSON.parse(response.body)
res.render('sessionDetails', { title: 'Sessions Details', session: session, error: error })
}
}
request.get(options, callback)
})

router.get('/sessions/markRead/:id', function (req, res, next) {
console.log(req.session.userId)
var id = req.params.id
headers = {
'app_id': req.session.kiboappid,
'app_secret': req.session.kiboappsecret,
'content-type': 'application/json'
}
var options = {
url: `https://staging.kibopush.com/api/sessions/markread/${id}`,
headers: headers,
rejectUnauthorized: false
}

function callback (error, response, body) {
console.log('Response-Body', response.body)
if (!error && response.statusCode === 200) {
console.log('Response-Parse', JSON.parse(response.body))
var info = JSON.parse(response.body)
var chatSeen
chatSeen = info.payload
console.log(chatSeen)
res.render('sessionDetails', { title: 'Sessions Details', session: session, chats: chats, chatSeen: chatSeen })
} else {
var errorChatSeen = JSON.parse(response.body)
res.render('sessionDetails', { title: 'Sessions Details', session: session, chats: chats, chatSeen: chatSeen, errorChatSeen: errorChatSeen })
}
}
request.get(options, callback)
})

router.get('/sessions/liveChat/:id', function (req, res, next) {
console.log(req.session.userId)
var id = req.params.id
headers = {
'app_id': req.session.kiboappid,
'app_secret': req.session.kiboappsecret,
'content-type': 'application/json'
}
var options = {
url: `https://staging.kibopush.com/api/livechat/${id}`,
headers: headers,
rejectUnauthorized: false
}

function callback (error, response, body) {
console.log('Response-Body', response.body)
if (!error && response.statusCode === 200) {
console.log('Response-Parse', JSON.parse(response.body))
var info = JSON.parse(response.body)
var liveChat
liveChat = info.payload
console.log(liveChat)
res.render('liveChat', { title: 'Live Chat', liveChat: liveChat })
} else {
error = JSON.parse(response.body)
res.render('liveChat', {title: 'Live Chat', liveChat: liveChat, error: error})
}
}
request.get(options, callback)
})

module.exports = router
2 changes: 1 addition & 1 deletion routes/workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ router.get('/workflows', function (req, res, next) {
if (!error && response.statusCode === 200) {
console.log('Response-Parse', JSON.parse(response.body))
var info = JSON.parse(response.body)
var workflows = info
var workflows = info.payload
res.render('workflows', { title: 'Workflows', workflows: workflows })
} else {
error = JSON.parse(response.body)
Expand Down
2 changes: 1 addition & 1 deletion views/index.jade
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends sidebar
block div#content
div#main
h1 Welcome to KiboPush Sample Client Application for calling API
h1(style='padding: 10px') Welcome to KiboPush Sample Client Application for calling API
div#divCredential
h3 Enter your credentials
form(action="/",method="post")
Expand Down
69 changes: 69 additions & 0 deletions views/liveChat.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
extends sidebar
block div#content
div#divInformation
h1= title
div#divDatadiv.table-scrollable
div(class = "control-group span6")
label
| Search :

input(type="search" class="light-table-filter form-control input-medium input-inline" data-table="liveChat" placeholder="Enter search term")
table(class = "table table-striped table-bordered table-hover liveChat")
thead
tr
td
span
|Format
td
span
|Sender Id
td
span
|Recipient Id
td
span
|Sender Facebook Id
td
span
|Recipient Facebook Id
td
span
|Status
td
span
|Date Time
td
span
|Url Meta
td
span
|Payload

tbody
if (liveChat)
form(action="/downloadcsv",method="post")
- var dd=JSON.stringify(liveChat)
input(type="hidden" name ="dd" value = dd)

if (liveChat.length != 0)
- each object in liveChat
tr
td=object.format
td=object.sender_id
td=object.recipient_id
td=object.sender_fb_id
td=object.recipient_fb_id
td=object.status
td=object.datetime
td=object.url_meta
td(colspan = 12)=JSON.stringify(object.payload)
tr
td(colspan = 12,style = "text-align:right;")
button(class = "downloadcsv btn btn-info" type="submit")
|Export Record in CSV
else
tr
td(colspan = 12,style = "text-align:center;")="No live chat record found."
else
tr
td(colspan = 8,style = "text-align:center;")="No live chat record found. " + error.description
152 changes: 152 additions & 0 deletions views/sessionDetails.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
extends sidebar
block div#content
div#divInformation
h1= title
div#divDatadiv.table-scrollable
div(class = "control-group span6")
label
| Search :

input(type="search" class="light-table-filter form-control input-medium input-inline" data-table="session" placeholder="Enter search term")
table(class = "table table-striped table-bordered table-hover session")
thead
tr
td
span
|Id
td
span
|Chats
td
span
|Subscriber Id
td
span
|Page Id
td
span
|Company Id
td
span
| Status
td
span
|Request Time
td
span
|Mark Read
td
span
|View Live Chat

tbody
if (session)
form(action="/downloadcsv",method="post")
- var dd=JSON.stringify(session)
input(type="hidden" name ="dd" value = dd)
td=session._id
td=chats.length
td=session.subscriber_id._id
td=session.page_id._id
td=session.company_id
td=session.status
td=session.request_time
td
a(href='/sessions/markRead/' + session._id) Mark Read
td
a(href='/sessions/liveChat/' + session._id) View LiveChat
tr
td(colspan = 12,style = "text-align:right;")
button(class = "downloadcsv btn btn-info" type="submit")
|Export Record in CSV
else
tr
td(colspan = 8,style = "text-align:center;")="No record found. " + error.description
if (typeof chatSeen != 'undefined')
div.divDatadiv.table-scrollable
h3='Chat Marked Seen Response'
table(class = "table table-striped table-bordered table-hover session")
thead
tr
td
span
|Status
td
span
|No.of Chats Modified
td
span
|No.of Chat
tbody
td=chatSeen.ok
td=chatSeen.nModified
td=chatSeen.n

div.divDatadiv.table-scrollable
h3='Chats'
div(class = "control-group span6")
label
| Search :

input(type="search" class="light-table-filter form-control input-medium input-inline" data-table="chats" placeholder="Enter search term")
table(class = "table table-striped table-bordered table-hover chats")
thead
tr
td
span
|Format
td
span
|Sender Id
td
span
|Recipient Id
td
span
|Sender Facebook Id
td
span
|Recipient Facebook Id
td
span
|Session Id
td
span
|Company Id
td
span
|Status
td
span
|Date Time
td
span
|Payload
tbody
if (chats)
form(action="/downloadcsv",method="post")
- var dd=JSON.stringify(chats)
input(type="hidden" name ="dd" value = dd)
if (chats.length != 0)
- each chat in chats
tr
td=chat.format
td=chat.sender_id
td=chat.recipient_id
td=chat.sender_fb_id
td=chat.recipient_fb_id
td=chat.session_id
td=chat.company_id
td=chat.status
td=chat.datetime
td=JSON.stringify(chat.payload)
tr
td(colspan = 12,style = "text-align:right;")
button(class = "downloadcsv btn btn-info" type="submit")
|Export Record in CSV
else
tr
td(colspan = 12,style = "text-align:center;")="No record found. "
else
tr
td(colspan = 12,style = "text-align:center;")="No record found. " + error.description
15 changes: 8 additions & 7 deletions views/sessions.jade
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ block div#content

if (sessions != 0)
- each session in sessions
tr
td=session._id
td=session.subscriber_id._id
td=session.page_id._id
td=session.company_id
td=session.status
td=session.request_time
tr
td
a(href='/sessions/' + session._id) #{session._id}
td=session.subscriber_id._id
td=session.page_id._id
td=session.company_id
td=session.status
td=session.request_time
tr
td(colspan = 8,style = "text-align:right;")
button(class = "downloadcsv btn btn-info" type="submit")
Expand Down
Loading

0 comments on commit 4bc4a53

Please sign in to comment.