Commit d806084d by Anna Sokolova

new commit

0 parents
node_modules/
audio/
logs/
threads/
package-lock.json
log.txt
MIT License
Copyright (c) 2020 Dasha Samples
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# How to start the application
Megafon inline support on Dasha.AI platform Prerecord Development version
1. Clone the repo and install the dependencies:
```sh
git clone git@gitlab.veeble.ru:Anna/avito-test-work.git
cd avito-test-work
touch log.txt
mkdir -p stt audio
chmod a+rw log.txt logs threads audio app/phrasemap.json
npm install
```
2. To start a text chat, run:
```sh
npm start chat
```
3. To receive a phone call from Dasha, run:
```sh
npm start <your phone number>
```
The phone number should be in the international format without the `+` (e.g. `12223334455`)
{
"formatVersion": "2",
"dialogue": {
"file": "main.dsl"
},
"nlu": {
"language": "ru-RU",
"skills": [
"sentiment",
"common_phrases",
"common-numbers"
],
"customIntents": {
"file": "intents.json"
}
},
"nlg": {
"type": "phrases",
"file": "phrasemap.json",
"signatureFile": "phrasemap.json"
},
"name": "avito-test-work"
}
library
import "canHearYou.dsl";
import "dontUnderstand.dsl";
import "hangup.dsl";
import "hello.dsl";
import "repeatAndPing.dsl";
library
digression call_operator
{
conditions { on #messageHasAnyIntent(digression.call_operator.triggers); }
var retriesLimit = 2;
var counter = 0;
var resetOnRecognized=false;
var triggers = ["call_operator"];
var responses: Phrases[] = ["call_operator"];
do
{
$cjm.push("call_operator");
for (var item in digression.call_operator.responses)
{
#say(item, repeatMode: "ignore");
}
#repeat(accuracy: "repeat");
return;
}
transitions
{
}
}
\ No newline at end of file
library
digression can_hear_you
{
conditions { on #messageHasAnyIntent(digression.can_hear_you.triggers) priority -100; }
var triggers = ["can_you_hear_me"];
var responses: Phrases[] = ["i_can_hear_you"];
do
{
for (var item in digression.can_hear_you.responses)
{
#say(item, repeatMode: "ignore");
}
return;
}
transitions
{
}
}
library
context
{
output status:string?;
output serviceStatus:string?;
}
digression dont_understand_hangup_params
{
conditions { on false; }
var responses: Phrases[] = ["dont_understand_forward"];
var status = "DontUnderstandHangup";
var serviceStatus = "Done";
do
{
}
transitions
{
}
}
digression dont_understand
{
conditions { on true priority -1000; }
var retriesLimit=2;
var counter=0;
var resetOnRecognized=false;
var responses: Phrases[] = ["dont_understand"];
do
{
if (digression.dont_understand.counter == 2)
{
goto hangup;
}
set digression.dont_understand.counter=digression.dont_understand.counter+1;
set digression.dont_understand.resetOnRecognized = false;
for (var item in digression.dont_understand.responses)
{
#say(item, repeatMode: "ignore");
//#say("dont_understand_question");
}
#repeat(accuracy: "short");
return;
}
transitions
{
hangup: goto dont_understand_hangup;
}
}
preprocessor digression dont_understand_preprocessor
{
conditions { on true priority 50000; }
do
{
if (digression.dont_understand.resetOnRecognized)
{
set digression.dont_understand.counter = 0;
}
set digression.dont_understand.resetOnRecognized = true;
return;
}
transitions
{
}
}
node dont_understand_hangup
{
do
{
$cjm.push("dont_understand_hangup");
for (var item in digression.dont_understand_hangup_params.responses)
{
#say(item, repeatMode: "ignore");
}
set $status=digression.dont_understand_hangup_params.status;
set $serviceStatus=digression.dont_understand_hangup_params.serviceStatus;
//#forward("12223334455"); //use if you want to transfer a call
//#disconnect();
goto do_before_exit;
}
transitions
{
do_before_exit: goto do_before_exit;
}
}
library
context
{
output serviceStatus: string?;
}
digression hangup
{
conditions
{
on true tags: onclosed;
}
var serviceStatus = "UserHangup";
do
{
$cjm.push("hangup");
set $serviceStatus = digression.hangup.serviceStatus;
//#disconnect();
goto do_before_exit;
}
transitions
{
do_before_exit: goto do_before_exit;
}
}
library
/**
* Reaction if nothing meaningful happens in the dialogue for too long.
*/
preprocessor digression hello
{
conditions { on #getIdleTime() - digression.hello.lastIdleTime > digression.hello.idleTimeLimit tags: ontick; }
var idleTimeLimit=8000;
var lastIdleTime=0;
var retriesLimit=2;
var counter=0;
do
{
set digression.hello.lastIdleTime=#getIdleTime();
if (digression.hello.counter > digression.hello.retriesLimit)
{
goto hangup;
}
set digression.hello.counter=digression.hello.counter+1;
#say("hello", repeatMode: "ignore");
// #say("dont_understand_question");
#repeat(accuracy: "short");
return;
}
transitions
{
hangup: goto hello_hangup;
}
}
preprocessor digression hello_preprocessor
{
conditions { on true priority 50000; }
do
{
set digression.hello.lastIdleTime = 0;
set digression.hello.counter = 0;
return;
}
transitions
{
}
}
node hello_hangup
{
do
{
$cjm.push("hello_hangup");
#say("dont_understand_hangup");
set $status="EmptyCall";
set $serviceStatus="Done";
//#disconnect();
goto do_before_exit;
}
transitions
{
do_before_exit: goto do_before_exit;
}
}
library
digression i_am_robot
{
conditions { on #messageHasAnyIntent(digression.i_am_robot.triggers); }
var triggers = ["are_you_a_robot"];
var responses: Phrases[] = ["yes_i_am_a_robot"];
do
{
for (var item in digression.i_am_robot.responses)
{
#say(item, repeatMode: "ignore");
}
#repeat(accuracy: "short");
return;
}
transitions
{
}
}
library
preprocessor digression machine
{
conditions { on #messageHasIntent("robot_marker") || #messageHasIntent("answering_machine") priority 110000; }
var visited = 0;
do
{
$cjm.push("machine_dig");
digression disable hello;
set $conversation_result = "автоответчик";
set $status = "wait_answer";
set digression.machine.visited += 1;
if(digression.machine.visited == 2 || (digression.wait_answer.visited == 1 && digression.machine.visited == 1)) {goto do_before_exit;}
return;
//wait *;
}
transitions
{
do_before_exit: goto do_before_exit;
cantalk: goto fitness_not_qualified on timeout 5000;
/*bot: goto answering_machine on #messageHasIntent("robot_marker");
someone: goto fitness_not_qualified on true;
maybe_bot: goto answering_machine on timeout 5000;*/
}
}
digression wait_answer // дигрессии
{
conditions
{
on #messageHasIntent("robot_marker") || #messageHasIntent("answering_machine") && digression.wait_answer.visited < 3 priority 110000;
}
var visited = 0;
do
{
$cjm.push("wait_answer_dig");
digression disable hello;
set $conversation_result = "автоответчик";
set $status = "wait_answer";
set digression.wait_answer.visited += 1;
if(digression.wait_answer.visited == 2 || (digression.wait_answer.visited == 1 && digression.machine.visited == 1)) {goto do_before_exit;}
wait *;
}
transitions
{
do_before_exit: goto do_before_exit;
cantalk: goto fitness_not_qualified on timeout 5000;
/*bot: goto answering_machine on #messageHasIntent("robot_marker");
someone: goto fitness_not_qualified on true;
maybe_bot: goto answering_machine on timeout 5000;*/
}
}
/*digression ivr // дигрессии
{
conditions
{
on #messageHasIntent("robot_marker") && digression.wait_answer.visited == 0 && digression.ivr.visited < 3 priority 110000;
}
var visited = 0;
do
{
$cjm.push("ivr_dig");
set $status = "ivr";
set digression.ivr.visited += 1;
set $conversation_result = "автоответчик";
return;
}
transitions
{
}
}*/
node fitness_not_qualified
{
do
{
$cjm.push("fitness_not_qualified");
// #say("deal");
digression enable {repeat, hello};
#waitingMode(duration: 2000);
wait *;
}
transitions
{
bot: goto its_machine on #messageHasAnyIntent(["robot_marker", "answering_machine"]);
//yes: goto offer on #messageHasAnyIntent(["accept", "what_question"]) || #messageHasSentiment("positive") && !#messageHasAnyIntent(["decline", "cant_talk_rn"]);
//no_busy: goto letme_40sec on (#messageHasAnyIntent(["decline", "cant_talk_rn", "call_later"]) || #messageHasSentiment("negative")) && !#messageHasIntent("not_interested");
//time: goto been_registred on timeout 10000;
// other: goto offer on true;
}
onexit
{
}
}
node its_machine
{
do
{
$cjm.push("its_machine");
set $status = "voice_menu";
wait *;
}
transitions
{
//someone: goto fitness_not_qualified on #messageHasIntent("can_you_hear_me") priority -100;
bot: goto answering_machine on #messageHasAnyIntent(["robot_marker", "answering_machine"]);
someone: goto fitness_not_qualified on true;
maybe_bot: goto answering_machine on timeout 5000;
//targeted_action_vm_nqa_1: goto fitness_not_qualified on true;
}
}
node answering_machine
{
do
{
$cjm.push("answering_machine");
//#waitingMode(duration: 1500);
digression disable {repeat, dont_understand, can_hear_you};
set $status = "answering_machine";
goto do_before_exit;
//exit;
}
transitions
{
do_before_exit: goto do_before_exit;
//targeted_action_bot_yes: goto fitness_validation_yes;
//off_target_action_am: goto root;
}
onexit
{
default: do
{
set $conversation_result = "автоответчик";
}
}
}
\ No newline at end of file
library
preprocessor digression repeat_preprocessor
{
conditions { on true priority 50000; }
var retriesLimit=2;
var counter=0;
do
{
if (digression.repeat.resetOnRecognized)
{
set digression.repeat.counter = 0;
#log(digression.repeat.counter);
}
set digression.repeat.resetOnRecognized = true;
#log(digression.repeat.resetOnRecognized);
return;
}
transitions
{
}
}
digression repeat_hangup_params
{
conditions { on false; }
var responses: Phrases[] = ["dont_understand_hangup"];
var status = "RepeatHangup";
var serviceStatus = "Done";
do
{
}
transitions
{
}
}
digression repeat
{
conditions { on #messageHasAnyIntent(digression.repeat.triggers); }
var retriesLimit = 2;
var counter = 0;
var resetOnRecognized=false;
var triggers = ["repeat", "dont_understand", "what"];
var responses: Phrases[] = ["i_said"];
do
{
$cjm.push("repeat_dig");
if (digression.repeat.counter == digression.repeat.retriesLimit)
{
goto hangup;
}
set digression.repeat.counter = digression.repeat.counter + 1;
#log(digression.repeat.counter);
set digression.repeat.resetOnRecognized = false;
for (var item in digression.repeat.responses)
{
#say(item, repeatMode: "ignore");
}
#repeat(accuracy: "short");
return;
}
transitions
{
hangup: goto repeat_or_ping_hangup;
}
}
digression ping
{
conditions { on #messageHasAnyIntent(digression.ping.triggers) and !#messageHasIntent("greeting") priority -100; }
var retriesLimit = 2;
var counter = 0;
var resetOnRecognized=false;
var triggers = ["ping"];
do
{
$cjm.push("ping_dig");
if (digression.repeat.counter == digression.repeat.retriesLimit)
{
goto hangup;
}
set digression.repeat.counter = digression.repeat.counter + 1;
#log(digression.repeat.counter);
set digression.repeat.resetOnRecognized = false;
#repeat(accuracy: "short");
return;
}
transitions
{
hangup: goto repeat_or_ping_hangup;
}
}
node repeat_or_ping_hangup
{
do
{
$cjm.push("repeat_or_ping_hangup");
for (var item in digression.repeat_hangup_params.responses)
{
#say(item, repeatMode: "ignore");
}
set $status=digression.repeat_hangup_params.status;
set $serviceStatus=digression.repeat_hangup_params.serviceStatus;
//#disconnect();
goto do_before_exit;
}
transitions
{
do_before_exit: goto do_before_exit;
}
}
library
block doWait():doWaitMore {
start node root {
do {
#log("block 'doWait'");
wait*;
}
transitions {
transition1: goto wait_for_abonent_speech on timeout 5000;
}
}
node wait_for_abonent_speech {
do {
#sayText("Вы готовы продолжить?", repeatMode: "ignore");
wait*;
}
transitions {
yes: goto stopwaiting on #messageHasSentiment("positive") || #messageHasIntent("ready");
maybe: goto root on true && !#messageHasSentiment("positive") && !#messageHasIntent("ready") && !#messageHasSentiment("negative");
no: goto waiting on #messageHasSentiment("negative");
}
}
node waiting {
do {
#sayText("Жду.", repeatMode: "ignore");
goto root;
}
transitions{
root: goto root;
}
}
node stopwaiting {
do {
// return value from block
return "yes";
}
}
}
digression wait_for_abonent
{
conditions { on #messageHasAnyIntent(digression.wait_for_abonent.triggers); }
var triggers = ["wait", "waitfor"];
var responses: Phrases[] = ["imwaiting"];
do
{
$cjm.push("wait_for_abonent");
for (var item in digression.wait_for_abonent.responses)
{
#say(item, repeatMode: "ignore");
}
var block_result = blockcall doWait();
if (block_result == "yes")
{
#sayText("Давайте продолжим", repeatMode: "ignore");
#repeat(accuracy:"short");
return;
}
}
transitions
{
}
}
\ No newline at end of file
library
digression when_callback
{
conditions { on #messageHasIntent("when_callback") && !#messageHasIntent("notAboutCallback") priority 100; }
var responses: Phrases[] = ["willcallback"];
do
{
$cjm.push("when_callback");
for (var item in digression.when_callback.responses)
{
#say(item, repeatMode: "ignore");
//#sayText("У вас остались еще вопросы?");
}
#repeat(accuracy:"short");
return;
}
transitions
{
}
}
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
{
"default": {
"voiceInfo": {
"emotion": "good",
"lang": "ru-RU",
"speaker": "alena",
"speed": 1.0
},
"phrases": {
"hello": {
"random": [
[
{
"text": "Алло"
}
],
[
{
"text": "Ало?"
}
],
[
{
"text": "Вы меня слышите?"
}
]
]
},
"i_said": [
{
"text": "Я говорю"
}
],
"i_will_wait": {
"random": [
[
{
"text": "Хорошо, я жду"
}
],
[
{
"text": "Конечно, я подожду"
}
],
[
{
"text": "Хорошо, жду"
}
]
]
},
"i_can_hear_you": [
{
"text": "Да. Я вас слышу."
}
],
"dont_understand": {
"random": [
[
{
"text": "Извините, можете повторить?"
}
],
[
{
"text": "Извините, что то со связью, можете повторить?"
}
],
[
{
"text": "Извините, не расслышала"
}
],
[
{
"text": "Повторите пожалуйста?"
}
]
]
},
"dont_understand_hangup": [
{
"text": "Что то со связью, плохо вас слышно. Пожалуйста, перезвоните. До свидания!"
}
],
"dont_understand_forward": [
{
"text": "Вы знаете, я вас очень плохо слышу. Я сейчас переключу вас на другого оператора"
}
],
"greeting": [
{
"text": "Алло, день добрый"
}
],
"greeting_2": [
{
"text": "Добрый день! Вы мебелью занимаетесь сейчас?"
}
],
"let_me_40sec": [
{
"text": "Я всего в 40 секундах, позволите?"
}
],
"already_client": [
{
"text": "отлично. Тогда наш менеджер подготовит для вас бесплатные рекомендации по точкам роста на площадке. До этого я хотел бы задать пару вопросов. Вы уже Довольны результатом от размешения на авито?"
}
],
"end_conversation_1": [
{
"text": "Я вас понял, всего вам доброго!"
}
],
"end_conversation_2": [
{
"text": "Хорошо, я перезвоню Вам позднее, до свидания!"
}
],
"end_conversation_3": [
{
"text": "Спасибо, что уделили время!До свидания!"
}
],
"end_conversation_4": [
{
"text": "Понял вас! Я передам информацию нашему менеджер - он наберет вам и расскажет подробнее, Спасибо, что уделили время."
}
],
"end_conversation_5": [
{
"text": "Понял вас. Спасибо! До свидания"
}
],
"offer": {
"first": [
{
"text": "Мы занимаемся выводом производителей и продавцов мебели на авито, так как мебель сейчас входит топ-5 самых продаваемых ниш. сейчас ищем партнёров, которые готовы получать 2-3 новые заявки в день , подскажите вам может быть это интересно?"
}
],
"short": [
{
"text": "Я хотел бы пригласить вас на бесплатную консультацию, где мы расскажем как можно получить лиды с авито?"
}
]
},
"offer_2": [
{
"text": "У нас сейчас отличные результаты с клиентами на Авито ,которые получают хороший поток клиентов. Вас заявки вообще по 400 рублей интересует?"
}
],
"ask_if_client": [
{
"text": "Хорошо. Давайте я задам пару вопросов, после этого менеджер наберет вам и расскажет подробнее. Вы уже размещаетесь на авито?"
}
],
"ask_price": [
{
"text": "По какой цене сейчас обходится заявка?"
}
],
"answer": [
{
"text": "Это поможет нам подготовитсья к консультации. Уточните пожалуйста довольны ли вы результатом?"
}
],
"ask_if_satisfied": [
{
"text": "Отлично! Вы довольны результатом?"
}
],
"when_call": [
{
"text": "Отлично! Я передам информацию нашему менеджеру. Когда вам будет удобно переговоить с ним?"
}
],
"why_need_it_1": [
{
"text": "Это поможет нам подготовитсья к консультации. Уточните пожалуйста - вы уже работаете на авито?"
}
],
"why_need_it_2": [
{
"text": "Это поможет нам подготовитсья к консультации. Уточните пожалуйста довольны ли вы результатом?"
}
],
"where_number": [
{
"text": "Увидел вас в списке продавцов и производителей мебели."
}
],
"who_are_you": [
{
"text": "Меня зовут Иван, агентство R-брокер, премиум-партнёры площадки Авито."
}
],
"what_conditions": [
{
"text": "Более подробно про все условия сможет расскажет менеджер, в любом случае эта бесплатная консультация. Вы уже размещаетесь на авито?"
}
],
"dont_sell": [
{
"text": "Извините, видимо ошибся. Спасибо, до свидания."
}
],
"no_shop": [
{
"text": "Я вас поняла. Спасибо, что уделили время! До свидания"
}
],
"not_lpr": [
{
"text": "Понял вас. С кажите а с кем можно переговорить по вопросу привлечения клиентов по мебели?"
}
]
},
"types": {},
"macros": {
"hello": {},
"i_said": {},
"sorry_wont_call": {},
"i_will_wait": {},
"i_can_hear_you": {},
"dont_understand": {},
"dont_understand_hangup": {},
"dont_understand_forward": {},
"dont_understand_question": {},
"mhm": {},
"yes_i_am_a_robot": {},
"is_that_all": {},
"end_conversation": {},
"non_work_greetings":{},
"non_work_goodbye":{},
"non_work_short_goodbye": {},
"something_else":{},
"im_wrighting":{},
"work_greetings": {},
"work_goodbye": {},
"ask_company_name": {},
"request_accepted": {},
"get_client_request": {},
"get_cell_phone": {},
"check_is_shared": {},
"get_phone_suffix": {},
"get_another_phone": {},
"greeting": {},
"greeting_2": {},
"offer": {},
"offer_2": {},
"let_me_40sec": {},
"already_client": {},
"ask_if_client": {},
"ask_if_satisfied": {},
"ask_price": {},
"when_call": {},
"answer": {},
"why_need_it_1": {},
"why_need_it_2": {},
"where_number": {},
"who_are_you": {},
"dont_sell": {},
"no_shop": {},
"not_lpr": {},
"what_conditions": {},
"end_conversation_1": {},
"end_conversation_2": {},
"end_conversation_3": {},
"end_conversation_4": {},
"end_conversation_5": {}
}
}
}
\ No newline at end of file
{
"node::root": {
"common.position": {
"x": 600,
"y": 0
}
},
"node::caller_id": {
"common.position": {
"x": 598.377372534425,
"y": 134.60160992786908
}
},
"node::end_conversation": {
"common.position": {
"x": 600,
"y": 1090.3536507636595
}
},
"node::do_before_exit": {
"common.position": {
"x": 600,
"y": 709.2035244482049
}
},
"node::repeat_or_ping_hangup": {
"common.position": {
"x": 0,
"y": 415
}
},
"node::hello_hangup": {
"common.position": {
"x": 0,
"y": 220
}
},
"node::dont_understand_hangup": {
"common.position": {
"x": 0,
"y": 715
}
},
"node::conversation_done": {
"common.position": {
"x": 1480,
"y": 966.137946142489
}
},
"node::wait_message": {
"common.position": {
"x": 2080,
"y": 644.8260546478509
}
},
"node::get_abonent_name": {
"common.position": {
"x": 1480,
"y": 851.0084920989109
}
},
"node::check_abonent_name": {
"common.position": {
"x": 2080,
"y": 893.0535799922327
}
},
"node::say_wrote": {
"common.position": {
"x": 2080,
"y": 770.7061811030865
}
},
"node::add_message": {
"common.position": {
"x": 1480,
"y": 533.057587652757
}
},
"node::ping": {
"common.position": {
"x": 0,
"y": 315
}
},
"node::repeat": {
"common.position": {
"x": 0,
"y": 515
}
},
"node::repeat_hangup_params": {
"common.position": {
"x": 600,
"y": 530
}
},
"node::repeat_preprocessor": {
"common.position": {
"x": 600,
"y": 475
}
},
"node::hello_preprocessor": {
"common.position": {
"x": 600,
"y": 585
}
},
"node::hello": {
"common.position": {
"x": 0,
"y": 115
}
},
"node::hangup": {
"common.position": {
"x": 0,
"y": 20
}
},
"node::dont_understand_preprocessor": {
"common.position": {
"x": 600,
"y": 370
}
},
"node::dont_understand": {
"common.position": {
"x": 0,
"y": 810
}
},
"node::dont_understand_hangup_params": {
"common.position": {
"x": 600,
"y": 420
}
},
"node::can_hear_you": {
"common.position": {
"x": 600,
"y": 645
}
},
"node::exit_dig": {
"common.position": {
"x": 0,
"y": 615
}
},
"node::no_message": {
"common.position": {
"x": 1480,
"y": 734.0697783815012
}
},
"node::non_work_branch": {
"common.position": {
"x": 1046.6676796891302,
"y": 324.76777774720415
}
},
"node::request_accepted": {
"common.position": {
"x": 2680,
"y": 1029.454349255128
}
},
"node::get_client_questions": {
"common.position": {
"x": 2680,
"y": 868.8603922782834
}
},
"node::get_cell_phone": {
"common.position": {
"x": 3280,
"y": 575.5801672846062
}
},
"node::is_shared_phone": {
"common.position": {
"x": 3280,
"y": 389.5873927822081
}
},
"node::check_shared_phone": {
"common.position": {
"x": 2680,
"y": 679.7473236381277
}
},
"node::get_company_name": {
"common.position": {
"x": 2680,
"y": 224.565654864841
}
},
"node::get_another_phone": {
"common.position": {
"x": 3280,
"y": 10.131652410874324
}
},
"node::phone_confirmation": {
"common.position": {
"x": 2680,
"y": 42.55689227944265
}
},
"node::ask_client_name": {
"common.position": {
"x": 2080,
"y": 306.0375290687854
}
},
"node::check_client_name": {
"common.position": {
"x": 2080,
"y": 148.12143450145916
}
},
"node::by_work_branch": {
"common.position": {
"x": 2080,
"y": 26.98742096578726
}
},
"node::get_alter_company_name": {
"common.position": {
"x": 3280,
"y": 136.54309920643223
}
},
"node::check_mobile_code": {
"common.position": {
"x": 2680,
"y": 425.40569848894876
}
}
}
\ No newline at end of file
const fs = require("fs");
const path = require("path");
class AudioResources
{
constructor()
{
this.resources = {};
}
getResourceKey(text, voiceInfo) {
return [
voiceInfo.lang ?? "",
voiceInfo.speaker ?? "",
voiceInfo.emotion ?? "Neutral",
voiceInfo.speed ?? 1,
voiceInfo.variation ?? 0,
text,
].join("|");
}
async appendJson(folder, pack)
{
const errors = [];
let i = 0;
for (const phrase of pack.phrases ?? []) {
i++;
// валидация
if (phrase.phrase === undefined) {
errors.push(`For ${i} phrase field 'phrase' is undefined`);
continue;
}
if (phrase.audio === undefined) {
errors.push(`For ${i} phrase field 'audio' is undefined`);
continue;
}
const audioFile = path.join(folder, phrase.audio);
if (!fs.existsSync(audioFile)) {
errors.push(`For ${i} phrase '${phrase.phrase}' file not found`);
continue;
}
phrase.voice = { ...pack.voice, ...phrase.voice };
const resourceKey = this.getResourceKey(phrase.phrase, phrase.voice ?? {});
if (resourceKey in this.resources) {
// дубликат - не ошибка
console.warn("Skip", i, "phrase because it's duplicate");
continue;
}
this.resources[resourceKey] = audioFile;
}
if (errors.length > 0)
{
console.error(`Was errors: ${JSON.stringify(errors, undefined, 2)}`);
return false;
}
return true;
}
async addFolder(folder)
{
const files = fs.readdirSync(folder);
let result = false;
for (const fileName of files)
{
if (path.extname(fileName) === ".json")
{
const fname = path.join(folder, fileName);
console.log(`Parsing ${fname}`);
result = await this.appendJson(folder, JSON.parse(fs.readFileSync(fname).toString()));
}
}
return result;
}
GetPath(text, voiceInfo)
{
const key = this.getResourceKey(text, voiceInfo);
const fpath = this.resources[key];
if (fpath === undefined)
throw new Error(`Failed to get ${key}`);
return fpath;
}
}
module.exports = AudioResources;
\ No newline at end of file
module.exports = exports = {
mobile_codes() {
return [
"900", "902", "903",
"904", "905", "906",
"908", "909", "950",
"951", "953", "960",
"961", "962", "963",
"964", "965", "966",
"967", "968", "969",
"980", "983", "986",
"901", "910", "911",
"912", "913", "914",
"915", "916", "917",
"918", "919", "978",
"981", "982", "984",
"985", "987", "988",
"989", "920", "921",
"922", "923", "924",
"925", "926", "927",
"928", "929", "930",
"931", "932", "933",
"934", "936", "937",
"938", "939", "999",
"952", "958", "977",
"991", "992", "993",
"994", "995", "996"
];
}
};
\ No newline at end of file
This diff is collapsed. Click to expand it.
{
"name": "avito-test-work",
"version": "1.0.0",
"description": "",
"author": "",
"license": "MIT",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"devDependencies": {
"prettier": "^2.3.0"
},
"dependencies": {
"string": "^3.3.3",
"moment": "^2.29.1",
"@dasha.ai/sdk": "^0.8.5"
}
}
This diff is collapsed. Click to expand it.
const axios = require("axios");
// Uncomment next URL only for authorization testing
// const api_method_send_path = "gate.smsaero.ru/v2/auth";
// Uncomment next URL for send SMS by authorized service user
const api_method_send_path = "gate.smsaero.ru/v2/sms/send";
const api_method_send = "https://" + api_method_send_path;
const api_username = 'ai@sales-mc.com';
const api_password = 'lOpVI_GrMOCe0VnUlpe9gA63nGkhmP_-';
const api_headers = { Accept: "application/json", Language: "ru-RU" };
const api_sign = "SMS Aero";
const api_auth = { username: api_username, password: api_password };
const api_options = { headers: api_headers, auth: api_auth };
module.exports = exports = {
/*
* Function for send text to abonent by Short Message Service
*
* Input params:
* number - abonent phone number from input param 'caller'
* text - text for send to abonent by Short Message Service
*
* Output params
* boolean: true|false
*
* ----------------------------------------------
* Usage in index.js for define external function
* ----------------------------------------------
*
* const sms = require("./sms-send");
*
* app.setExternal("send_sms", async (args, conv) => {
* let result = await sms.send_sms_text(args.phone, args.message);
* if (!result.success) console.log(result);
* return result.success;
* });
*
* ------------------------------------------------
* Usage in main.dsl for activate external function
* ------------------------------------------------
*
* external function send_sms(phone: string, message: string): boolean;
*
* --------------------------------------------
* Usage in any DSL for send message to abonent
* --------------------------------------------
*
* external send_sms(caller, "SMS text fo abonent");
*
*/
async send_sms_text (number, text) {
let result = {};
const params = { number: number, text: text, sign: api_sign };
let post_data = JSON.stringify(params);
api_options.params = params;
try {
result = await axios.get(api_method_send, api_options);
} catch (err) {
let error = err;
if (error.cause) error = error.cause;
if (error.response) error = {
status: error.response.status,
statusText: error.response.statusText,
method: error.response.request.method,
url: error.response.config.url,
path: error.response.request.path,
request_header: error.response.request._header,
};
result.data = {
"success": false,
"data": error,
"message": "axios crashed"
};
if (error.data) result.data = error.data;
}
return result.data;
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!