main.dsl 9.81 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
import "commonReactions/all.dsl";

context {
    input phone: string;
    input caller: string;
    input waiting: number;
    input about_abonent: string[];
    input about_fields: string[];

    output cjm: string[] = [];
    output need_ask_name: boolean = true;
    output template_id: number = 1;
    output conversation_start: number = 0;
    output conversation_begin: number = 0;
    output conversation_stop: number = 0;
    output conversation_status: string = "normal";
    output conversation_result: string = "";
    output abonent_request: string[] = [];
    output another_phone_number: string = "";
    output abonent_name: string = "";
    output company_name: string = "";
    output phone_suffix: string = "";
    output timer: string = "";
    output max_dialog_duration: number = 120000;
}

external function numbers_from_text(text: string): string;
external function dates_from_text(text: string): string;
external function part_of_the_day(): string;
external function is_empty(check: unknown): boolean;
external function sleep_ms(duration: number): unknown;
external function json_encode(object: unknown): string;
external function math_floor(value: number, presision: number|empty = 0): number;
external function math_round(value: number, presision: number|empty = 0): number;
external function math_ceil(value: number, presision: number|empty = 0): number;
external function phone_human(phone: string): string;
external function last_four(phone: string): string;
external function hours_now(): number;
external function check_mobile_code(phone: string): boolean;
external function countWords(message: string): number;

start node root
{
    do
    {
        $cjm.push("root");
        set $conversation_start = #getCurrentTime();
        goto caller_id;
    }
    transitions
    {
        caller_id: goto caller_id;
    }
}

block SkipMessagesBlock():boolean
{
    start node root
    {
        do
        {
            return true;
        }
    }
}
preprocessor digression timer_control // препроцессор с проверкой истечения таймера
{
    conditions
    {
        on true priority 100000;
    }    
    do
    {
       
        if(#isTimerExpired($timer)){
            set $conversation_result = "автоответчик";
            goto do_before_exit;
        
        }
        return;
    }
    transitions
    {
        do_before_exit: goto do_before_exit;

    }
}

node caller_id
{
    do
    {
        $cjm.push("caller_id");

        #connectSafe($phone);
        #waitForSpeech(1000);
        //таймер ограничения длинны рахговора
        set $timer = #startTimer($max_dialog_duration);

        // Запоминаем временной штамп перед самой первой репликой
        set $conversation_begin = #getCurrentTime();

        #say("greeting");
        var result = blockcall SkipMessagesBlock();
        wait *;
    }
    transitions
    {
        continue: goto continue on true;
    }

}

node continue
{
    do
    {
        $cjm.push("continue");        
        #say("greeting_2");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
    transitions
    {
        continue: goto offer on #messageHasAnyIntent(["what_question", "accept", "agree"]);
        time: goto offer on timeout 5000;
        busy: goto let_me_40sec on #messageHasAnyIntent(["cant_talk_rn", "call_later"]);
        rejection: goto end_conversation_1 on #messageHasAnyIntent(["decline", "not_interested", "mistake"]);
    }
    onexit
    {
        rejection: do {
            set $conversation_result = "отказ";
        }
    }
}

node let_me_40sec
{
    do
    {
        $cjm.push("let_me_40sec");
        #say("let_me_40sec");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
    transitions
    {
        agreement: goto offer on #messageHasAnyIntent(["accept", "agree"]);
        rejection: goto end_conversation_2 on #messageHasIntent("decline");
    }
    onexit
    {
        rejection: do {
            set $conversation_result = "перезвонить";
        }
    }
}

node offer
{
    do
    {
        $cjm.push("offer");
        #say("offer");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        agreement: goto ask_if_client on #messageHasAnyIntent(["accept", "agree"]);
        rejection: goto offer_2 on #messageHasIntent("decline");
        alreagy_client: goto already_client on #messageHasIntent("already_client");
        
    }
    onexit
    {
        agreement: do {
            set $conversation_result = "согласие";
        }
    }
}

node already_client
{
    do
    {
        $cjm.push("already_client");
        #say("already_client");
        var result = blockcall SkipMessagesBlock();
    }
        transitions
    {
        ask_price: goto ask_price on true;
        
    }
    onexit
    {
        ask_price: do {
            var text = #getMessageText();
            #log(text);
        }
    }
}

node offer_2
{
    do
    {
        $cjm.push("offer_2");
        #say("offer_2");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        agreement: goto ask_if_client on #messageHasAnyIntent(["accept", "agree"]);
        rejection: goto end_conversation_3 on #messageHasIntent("decline");
        
    }
    onexit
    {
        agreement: do {
            set $conversation_result = "согласие";
        }
    }
}

node ask_if_client
{
    do
    {
        $cjm.push("ask_if_client");
        #say("ask_if_client");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        agreement: goto ask_if_satisfied on #messageHasAnyIntent(["accept", "agree"]);
        rejection: goto end_conversation_4 on #messageHasIntent("decline");
        why_need_it_1: goto why_need_it_1 on #messageHasIntent("why_need_it");
        
    }
    onexit
    {
        rejection: do {
            set $conversation_result = "перезвонить";
        }
    }
}

node ask_if_satisfied
{
    do
    {
        $cjm.push("ask_if_satisfied");
        #say("ask_if_satisfied");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        why_need_it_1: goto why_need_it_2 on #messageHasIntent("why_need_it");
        ask_price: goto ask_price on true;
        
    }
    onexit
    {
        ask_price: do {
            var text = #getMessageText();
            #log(text);
        }
    }
}

node why_need_it_1
{
    do
    {
        $cjm.push("why_need_it_1");
        #say("why_need_it_1");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        answer: goto ask_if_satisfied on true;
    }
    onexit
    {
        answer: do {
            var text = #getMessageText();
            #log(text);
        }
    }
}

node why_need_it_2
{
    do
    {
        $cjm.push("why_need_it_2");
        #say("why_need_it_2");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        answer: goto answer on true;
        
    }
    onexit
    {
        answer: do {
            var text = #getMessageText();
            #log(text);
        }
    }
}

node answer
{
    do
    {
        $cjm.push("answer");
        #say("answer");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        ask_price: goto ask_price on true;
        
    }
    onexit
    {
        ask_price: do {
            var text = #getMessageText();
            #log(text);
        }
    }
}

node ask_price
{
    do
    {
        $cjm.push("ask_price");
        #say("ask_price");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        when_call: goto when_call on true;
        
    }
    onexit
    {
        when_call: do {
            var text = #getMessageText();
            #log(text);
        }
    }
}

node when_call
{
    do
    {
        $cjm.push("when_call");
        #say("when_call");
        var result = blockcall SkipMessagesBlock();
        wait*;
    }
        transitions
    {
        end_conversation_3: goto end_conversation_3 on true;
        
    }
    onexit
    {
        end_conversation_3: do {
            var text = #getMessageText();
            #log(text);
        }
    }
}


node end_conversation_1
{
    do
    {
        $cjm.push("end_conversation_1");
        #say("end_conversation_1");
        goto do_before_exit;
    }
    transitions
    {
        do_before_exit: goto do_before_exit;
    }
}

node end_conversation_2
{
    do
    {
        $cjm.push("end_conversation_2");
        #say("end_conversation_2");
        goto do_before_exit;
    }
    transitions
    {
        do_before_exit: goto do_before_exit;
    }
}

node end_conversation_3
{
    do
    {
        $cjm.push("end_conversation_3");
        #say("end_conversation_3");
        goto do_before_exit;
    }
    transitions
    {
        do_before_exit: goto do_before_exit;
    }
}

node end_conversation_4
{
    do
    {
        $cjm.push("end_conversation_4");
        #say("end_conversation_4");
        goto do_before_exit;
    }
    transitions
    {
        do_before_exit: goto do_before_exit;
    }
}

node do_before_exit
{
    do
    {
        $cjm.push("do_before_exit");
        set $conversation_stop = #getCurrentTime();
        exit;
    }
}

digression where_number
{
    conditions { on #messageHasIntent("where_number"); }
    do
    {
        $cjm.push("where_number");
        #say("where_number");
        #repeat();
        var result = blockcall SkipMessagesBlock();
        return;
    }
}


global digression @exit_dig_global
{
    conditions { on true tags: onclosed; }
    do
    {
        $cjm.push("@exit_dig");
        set $conversation_status = "broken";
        set $conversation_stop = #getCurrentTime();
        exit;
    }
}