Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Anna Sokolova
/
avito-test-work
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2761bd39
authored
Mar 23, 2024
by
Nick N. Sukharev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Обновление модуля 'shared' до версии шаблона dasha-templates/developer/
1 parent
677b11a7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
16 deletions
shared.js
shared.js
View file @
2761bd3
...
...
@@ -4,7 +4,7 @@ const axios = require("axios");
const
moment
=
require
(
"moment"
);
const
strings
=
require
(
"string"
);
const
dataset
=
require
(
"./dataset"
);
const
sys
=
require
(
'child_process'
);
const
sys
=
require
(
"child_process"
);
const
cct_api
=
'http://cct.r-broker.ru/api/'
;
const
cct_key
=
'y8Bzq1C0vIwhcrl98emy04JauUlWd7glhvUo2TcWBSkdMYzrKS'
...
...
@@ -20,19 +20,11 @@ const api_hook_key = 'kd56h4jfhj54f62hjf6d8YgjL9';
const
api_hook
=
api_hook_url
+
'?key='
+
api_hook_key
;
const
tg_wa_hook_url
=
'https://ai.r-broker.ru/demo-hooks/voice-bot.php'
const
tg_wa_options
=
{
auth
:
{
username
:
'web'
,
password
:
'web'
}
};
const
ai_hooks_opts
=
{
auth
:
{
username
:
'web'
,
password
:
'web'
}
};
const
answering_machine_hook
=
'https://ai.r-broker.ru/demo-hooks/check-answering-machine.php'
;
const
mobile_codes
=
dataset
.
mobile_codes
();
function
empty
(
value
)
{
if
(
value
===
undefined
)
return
true
;
if
(
value
===
null
)
return
true
;
const
str
=
strings
(
value
);
if
(
str
==
""
)
return
true
;
if
(
str
.
trim
()
==
""
)
return
true
;
return
false
;
}
async
function
cct_api_service
(
service
,
api_request
)
{
let
post_data
=
JSON
.
stringify
(
api_request
);
let
headers
=
{
...
...
@@ -51,7 +43,12 @@ async function cct_api_service (service, api_request) {
module
.
exports
=
exports
=
{
empty
(
value
)
{
return
empty
(
value
);
if
(
value
===
undefined
)
return
true
;
if
(
value
===
null
)
return
true
;
const
str
=
strings
(
value
);
if
(
str
==
""
)
return
true
;
if
(
str
.
trim
()
==
""
)
return
true
;
return
false
;
},
// Веб-хук для отправки сообщений через Telegram и WhatsApp
...
...
@@ -61,7 +58,7 @@ module.exports = exports = {
let
result
=
{};
let
wrong_data
=
{
status
:
'error'
,
detail
:
'axios crashed'
};
try
{
result
=
await
axios
.
post
(
tg_wa_hook_url
,
post_data
,
tg_wa_option
s
);
result
=
await
axios
.
post
(
tg_wa_hook_url
,
post_data
,
ai_hooks_opt
s
);
}
catch
(
err
)
{
wrong_data
.
detail
=
JSON
.
stringify
(
err
,
undefined
,
2
);
result
.
data
=
wrong_data
;
...
...
@@ -70,6 +67,7 @@ module.exports = exports = {
return
result
.
data
;
},
// Веб-хук для передачи отчёта о разговоре на машину AI
async
ai_api_hook
(
action
,
web_hook_data
)
{
let
api_hook_action
=
api_hook
+
'&action='
+
action
;
let
post_data
=
new
url
.
URLSearchParams
(
web_hook_data
);
...
...
@@ -81,7 +79,7 @@ module.exports = exports = {
wrong_data
.
detail
=
JSON
.
stringify
(
err
,
undefined
,
2
);
result
.
data
=
wrong_data
;
}
if
(
empty
(
result
.
data
))
return
wrong_data
if
(
this
.
empty
(
result
.
data
))
return
wrong_data
return
result
.
data
;
},
...
...
@@ -96,6 +94,22 @@ module.exports = exports = {
return
'night'
;
},
dasha_format
(
abonent_phone
)
{
let
clean_phone
=
abonent_phone
.
replace
(
/
[^\d]
/g
,
''
);
var
size
=
clean_phone
.
length
;
if
(
size
==
11
)
{
prefix
=
clean_phone
.
substring
(
0
,
1
);
if
(
prefix
==
8
)
{
return
"7"
+
clean_phone
.
substring
(
1
);
}
return
clean_phone
}
if
(
size
==
10
)
{
return
"7"
+
clean_phone
;
}
return
clean_phone
;
},
human_format
(
abonent_phone
)
{
let
clean_phone
=
abonent_phone
.
replace
(
/
[^\d]
/g
,
''
);
var
size
=
clean_phone
.
length
;
...
...
@@ -148,12 +162,14 @@ module.exports = exports = {
return
clean_phone
;
},
async
cct_numbers_from_text
(
text
)
{
// Веб-хук для извлечения чисел из текста через Т.У.К.
async
cct_numbers_from_text
(
text
,
option
)
{
const
service
=
'markers-data'
;
request
=
{
debug
:
false
,
input
:
"text"
,
channel
:
"client"
,
multipliers
:
option
,
distance
:
{
"min"
:
0.166667
,
"mid"
:
0.166667
,
"max"
:
0.166667
},
language
:
"russian"
,
text
:
text
,
...
...
@@ -183,12 +199,14 @@ module.exports = exports = {
return
result
;
},
async
cct_dates_from_text
(
text
)
{
// Веб-хук для извлечения дат из текста через Т.У.К.
async
cct_dates_from_text
(
text
,
option
)
{
const
service
=
'markers-data'
;
request
=
{
debug
:
false
,
input
:
"text"
,
channel
:
"client"
,
multipliers
:
option
,
distance
:
{
"min"
:
0.166667
,
"mid"
:
0.166667
,
"max"
:
0.166667
},
language
:
"russian"
,
text
:
text
,
...
...
@@ -223,6 +241,56 @@ module.exports = exports = {
return
result
;
},
// Веб-хук для извлечения времени из текста через Т.У.К.
async
cct_times_from_text
(
text
,
option
)
{
const
service
=
'markers-data'
;
request
=
{
debug
:
false
,
input
:
"text"
,
channel
:
"client"
,
multipliers
:
option
,
distance
:
{
"min"
:
0.166667
,
"mid"
:
0.166667
,
"max"
:
0.166667
},
language
:
"russian"
,
text
:
text
,
triggers
:
[
{
name
:
"times"
,
markers
:
[
{
type
:
"date time"
}
]
}
]
};
const
response
=
await
cct_api_service
(
service
,
request
);
let
result
=
""
;
if
(
response
.
status
!==
"success"
)
return
result
;
for
(
trigger
of
response
.
result
)
{
if
(
trigger
.
state
===
"on"
)
{
if
(
trigger
.
name
===
"times"
)
{
for
(
i
in
trigger
.
details
)
{
found
=
trigger
.
details
[
i
];
for
(
j
in
found
)
{
element
=
found
[
j
];
pattern
=
element
.
pattern
??
""
;
if
((
pattern
===
"%time%"
)
&&
(
result
===
""
))
result
=
element
.
value
;
}
}
}
}
}
if
(
result
===
""
)
return
{
full
:
""
,
date
:
""
,
time
:
""
,
text
:
""
};
moment
.
locale
(
"ru"
);
const
result_date
=
result
.
replace
(
/
\s
.+$/
,
''
);
const
result_time
=
result
.
replace
(
/^.+
\s
/
,
''
);
const
result_text
=
moment
(
result_date
,
"YYYY-MM-DD"
).
format
(
"D MMMM"
)
+
' в '
+
result_time
;
return
{
full
:
result
,
date
:
moment
(
result_date
,
"YYYY-MM-DD"
).
format
(
"DD.MM.YYYY"
),
time
:
result_time
,
text
:
result_text
};
},
renew_last_log_file
(
last_text_file
)
{
let
sysCommand
=
'cat '
+
last_text_file
+
' >log.txt'
;
sys
.
exec
(
sysCommand
,
(
error
,
stdout
,
stderr
)
=>
{
...
...
@@ -352,6 +420,23 @@ module.exports = exports = {
app_id
:
app_id
,
job_id
:
job_id
};
},
// Веб-хук для проверки реплик по подозрению на автоответчик
async
check_answered_machine
(
text
)
{
let
post_data
=
new
url
.
URLSearchParams
({
text
:
text
});
let
wrong_data
=
{
status
:
'error'
,
load
:
0
,
weight
:
-
1
,
details
:
[]
};
try
{
var
result
=
await
axios
.
post
(
answering_machine_hook
,
post_data
,
ai_hooks_opts
);
}
catch
(
err
)
{
wrong_data
.
details
=
JSON
.
stringify
(
err
,
undefined
,
2
);
result
.
data
=
wrong_data
;
}
if
(
this
.
empty
(
result
.
data
))
return
wrong_data
return
result
.
data
;
}
};
Write
Preview
Markdown
is supported
Attach a file
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 post a comment