Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
node_crisp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
web
node_crisp
Commits
a30770fc
Commit
a30770fc
authored
May 31, 2021
by
Gabriel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Agrega cliente de Crisp y manejo de comunicaciones con el cliente
parent
4e3444a2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
0 deletions
+76
-0
crisp.js
crisp.js
+76
-0
No files found.
crisp.js
0 → 100644
View file @
a30770fc
var
Crisp
=
require
(
"node-crisp-api"
);
var
CrispClient
=
new
Crisp
();
const
config
=
require
(
'config'
);
var
identifier
=
config
.
get
(
'credenciales.crisp.identifier'
);
var
key
=
config
.
get
(
'credenciales.crisp.key'
);
let
SIGUIENTE_PASO
=
'siguiente_paso'
;
let
localData
=
{};
CrispClient
.
authenticate
(
identifier
,
key
);
async
function
sendTextMessage
(
website_id
,
session_id
,
message
)
{
await
CrispClient
.
websiteConversations
.
sendMessage
(
website_id
,
session_id
,
{
type
:
"text"
,
from
:
"operator"
,
origin
:
"chat"
,
content
:
message
}
);
}
async
function
sendPickerMessage
(
website_id
,
session_id
,
id
,
title
,
choices
)
{
await
CrispClient
.
websiteConversations
.
sendMessage
(
website_id
,
session_id
,
{
type
:
"picker"
,
from
:
"operator"
,
origin
:
"chat"
,
content
:
{
"id"
:
id
,
"text"
:
title
,
"choices"
:
choices
//array
}
}
);
}
async
function
getSiguientePaso
(
website_id
,
session_id
)
{
let
data
=
await
getUserData
(
website_id
,
session_id
);
return
data
[
SIGUIENTE_PASO
];
}
async
function
setSiguientePaso
(
website_id
,
session_id
,
siguientePaso
,
userData
)
{
if
(
userData
==
null
)
{
userData
=
await
getUserData
(
website_id
,
session_id
);
}
userData
[
SIGUIENTE_PASO
]
=
siguientePaso
;
return
await
updateUserData
(
website_id
,
session_id
,
userData
);
}
async
function
getUserData
(
website_id
,
session_id
)
{
let
data
=
localData
[
website_id
.
concat
(
session_id
)];
if
(
data
==
null
){
await
updateUserData
(
website_id
,
session_id
,
{});
return
getUserData
(
website_id
,
session_id
);
}
return
data
;
}
async
function
updateUserData
(
website_id
,
session_id
,
data
)
{
localData
[
website_id
.
concat
(
session_id
)]
=
data
;
}
module
.
exports
=
{
CrispClient
:
CrispClient
,
sendTextMessage
:
sendTextMessage
,
sendPickerMessage
:
sendPickerMessage
,
getSiguientePaso
:
getSiguientePaso
,
setSiguientePaso
:
setSiguientePaso
,
getUserData
:
getUserData
,
updateUserData
:
updateUserData
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment