Перейти к содержанию

Dialplan — основной

Файл: /etc/asterisk/extensions.conf

[general]
static=yes
writeprotect=no
priorityjumping=no
autofallthrough=yes
#include extensions_pause.conf
#include extensions_cdr.conf
#include extensions_outbound.conf
#include extensions_generated.conf
#include extensions_language.conf
[internal]
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
[internal-calls]
exten => 000,1,NoOp(=== Hotline 000 internal ===)
 same => n,Set(HOTLINE_QUEUE=${ODBC_GET_HOTLINE_QUEUE()})
 same => n,GotoIf($["${HOTLINE_QUEUE}" = ""]?hotline_disabled,1)
 same => n,NoOp(Hotline queue: ${HOTLINE_QUEUE})
 same => n,Answer()
 same => n,Queue(${HOTLINE_QUEUE},tT,,,300)
 same => n,Hangup()
exten => hotline_disabled,1,NoOp(Hotline disabled)
 same => n,Answer()
 same => n,Playback(callbox/system/callbox-invalid-input)
 same => n,Hangup()
exten => _XXX,1,NoOp(=== Internal call to ${EXTEN} ===)
 same => n,Set(ORG_PREFIX=${CHANNEL(endpoint):0:3})
 same => n,GotoIf($["${ORG_PREFIX}" != ""]?have_prefix)
 same => n,Set(ORG_PREFIX=${CUT(CONTEXT,-,1)})
 same => n(have_prefix),NoOp(ORG_PREFIX=${ORG_PREFIX})
 same => n,Set(DEST_ENDPOINT=${ORG_PREFIX}${EXTEN})
 same => n,NoOp(Calling ${DEST_ENDPOINT})
 same => n,Goto(${ORG_PREFIX}-context,${DEST_ENDPOINT},1)
 same => n,Hangup()
[globals]
[directed-pickup]
exten => _*8XXX,1,NoOp(=== Directed Pickup: ${EXTEN} ===)
 same => n,Set(CURRENT_DEVICE=${CHANNEL(endpoint)})
 same => n,NoOp(Current device: ${CURRENT_DEVICE})
 same => n,Set(TENANT_ID=${ODBC_GET_TENANT_BY_ENDPOINT(${CURRENT_DEVICE})})
 same => n,NoOp(Tenant ID: ${TENANT_ID})
 same => n,GotoIf($["${CURRENT_DEVICE}" = ""]?fail_no_endpoint,1)
 same => n,Set(ORG_PREFIX=${CURRENT_DEVICE:0:3})
 same => n,NoOp(Organization prefix: ${ORG_PREFIX})
 same => n,Set(TARGET_NUM=${EXTEN:2})
 same => n,NoOp(Target terminal number: ${TARGET_NUM})
 same => n,Set(TARGET_DEVICE=${ORG_PREFIX}${TARGET_NUM})
 same => n,NoOp(Target device: ${TARGET_DEVICE})
 same => n,Set(TARGET_TENANT=${ODBC_GET_TENANT_BY_ENDPOINT(${TARGET_DEVICE})})
 same => n,GotoIf($["${TARGET_TENANT}" = ""]?fail_not_found,1)
 same => n,GotoIf($[${TARGET_TENANT} != ${TENANT_ID}]?fail_wrong_tenant,1)
 same => n,NoOp(Attempting pickup: ${TARGET_DEVICE}@${ORG_PREFIX}-context)
 same => n,Pickup(${TARGET_DEVICE}@${ORG_PREFIX}-context)
 same => n,Hangup()
exten => fail_no_endpoint,1,NoOp(Error: Cannot determine current endpoint)
 same => n,Answer()
 same => n,Playback(an-error-has-occurred)
 same => n,Hangup()
exten => fail_not_found,1,NoOp(Error: Target endpoint ${TARGET_DEVICE} not found)
 same => n,Answer()
 same => n,Playback(ss-noservice)
 same => n,Hangup()
exten => fail_wrong_tenant,1,NoOp(Error: Target ${TARGET_DEVICE} belongs to different org)
 same => n,NoOp(Current tenant: ${TENANT_ID}, Target tenant: ${TARGET_TENANT})
 same => n,Answer()
 same => n,Playback(privacy-incorrect)
 same => n,Hangup()
[queue-logic]
exten => 999,1,NoOp(=== Test ODBC INSERT ===)
 same => n,Answer()
 same => n,Set(CURRENT_DEVICE=${CHANNEL(endpoint)})
 same => n,Set(TENANT_ID=${ODBC_GET_TENANT_BY_ENDPOINT(${CURRENT_DEVICE})})
 same => n,Set(RESULT=${ODBC_ADD_QUEUE_MEMBER(org1-queue1,PJSIP/org1-1001,555,123456789,555,${TENANT_ID})})
 same => n,NoOp(INSERT RESULT: ${RESULT})
 same => n,Playback(beep)
 same => n,Hangup()
exten => _*32.,1,NoOp(--- Начало интерактивной регистрации в CallBox ---)
 same => n,Set(Q_ID=${EXTEN:3})
 same => n,Answer()
 same => n,Wait(1)
 same => n,Set(CURRENT_DEVICE=${CHANNEL(endpoint)})
 same => n,Set(TENANT_ID=${ODBC_GET_TENANT_BY_ENDPOINT(${CURRENT_DEVICE})})
 same => n,NoOp(Detected TENANT_ID: ${TENANT_ID} for endpoint: ${CURRENT_DEVICE})
 same => n,Set(ORG_PREFIX=${CURRENT_DEVICE:0:3})
 same => n,Set(FULL_QUEUE_NAME=${ORG_PREFIX}-queue-${Q_ID})
 same => n,Set(QUEUE_EXISTS=${ODBC_CHECK_QUEUE_EXISTS(${FULL_QUEUE_NAME},${TENANT_ID})})
 same => n,GotoIf($["${QUEUE_EXISTS}" = "0"]?fail_queue_not_found,1)
 same => n,GoSub(play-localized,s,1(callbox-enter-operator))
 same => n,Read(OP_NUM,,5,,3,30)
 same => n,GotoIf($["${OP_NUM}" = ""]?fail_empty,1)
 same => n,Set(OPER_EXISTS=${ODBC_CHECK_OPERATOR(${OP_NUM},${TENANT_ID})})
 same => n,GotoIf($["${OPER_EXISTS}" = "0"]?fail_notfound,1)
 same => n,Set(OP_IN_QUEUE=${ODBC_CHECK_OPERATOR_IN_QUEUE(${FULL_QUEUE_NAME},${OP_NUM},${TENANT_ID})})
 same => n,GotoIf($["${OP_IN_QUEUE}" != "0"]?fail_already_in_queue,1)
 same => n,Set(INTERFACE_NAME=PJSIP/${CURRENT_DEVICE})
 same => n,Set(INTERFACE_IN_QUEUE=${ODBC_CHECK_INTERFACE_IN_QUEUE(${INTERFACE_NAME},${TENANT_ID})})
 same => n,GotoIf($["${INTERFACE_IN_QUEUE}" != "0"]?fail_interface_busy,1)
 same => n,Set(UNIQUEID=${STRFTIME(,,%s)})
 same => n,Set(RESULT=${ODBC_ADD_QUEUE_MEMBER(${FULL_QUEUE_NAME},${INTERFACE_NAME},${OP_NUM},${UNIQUEID},${OP_NUM},${TENANT_ID})})
 same => n,AddQueueMember(${FULL_QUEUE_NAME},${INTERFACE_NAME},,,${OP_NUM})
 same => n,Set(LOG_ID=${ODBC_LOG_QUEUE_ACTION(${OP_NUM},${INTERFACE_NAME},${FULL_QUEUE_NAME},login,${TENANT_ID})})
 same => n,NoOp(Logged queue login: operator=${OP_NUM} queue=${FULL_QUEUE_NAME} tenant=${TENANT_ID} log_id=${LOG_ID})
 same => n,GoSub(play-localized,s,1(callbox-login-success))
 same => n,Hangup()
exten => fail_empty,1,NoOp(Ошибка: Пустой ввод)
 same => n,GoSub(play-localized,s,1(callbox-invalid-input))
 same => n,Hangup()
exten => fail_notfound,1,NoOp(Ошибка: Оператор ${OP_NUM} не найден в БД)
 same => n,GoSub(play-localized,s,1(callbox-operator-not-found))
 same => n,Hangup()
exten => fail_already_in_queue,1,NoOp(Ошибка: Оператор ${OP_NUM} уже зарегистрирован в другой очереди)
 same => n,GoSub(play-localized,s,1(callbox-already-in-queue))
 same => n,Hangup()
exten => fail_interface_busy,1,NoOp(Ошибка: Терминал ${CURRENT_DEVICE} уже используется другим оператором)
 same => n,GoSub(play-localized,s,1(callbox-terminal-busy))
 same => n,Hangup()
exten => fail_queue_not_found,1,NoOp(Ошибка: Очередь ${FULL_QUEUE_NAME} не найдена в БД)
 same => n,GoSub(play-localized,s,1(callbox-queue-not-found))
 same => n,Hangup()
exten => *33,1,NoOp(--- Выход из CallBox Realtime ---)
 same => n,Answer()
 same => n,Wait(1)
 same => n,Set(CURRENT_DEVICE=${CHANNEL(endpoint)})
 same => n,Set(INTERFACE_NAME=PJSIP/${CURRENT_DEVICE})
 same => n,Set(TENANT_ID=${ODBC_GET_TENANT_BY_ENDPOINT(${CURRENT_DEVICE})})
 same => n,Set(IS_REGISTERED=${ODBC_CHECK_INTERFACE_IN_QUEUE(${INTERFACE_NAME},${TENANT_ID})})
 same => n,GotoIf($["${IS_REGISTERED}" = "0"]?fail_not_registered,1)
 same => n,Set(OP_NUM=${ODBC_GET_OPERATOR_BY_INTERFACE(${INTERFACE_NAME},${TENANT_ID})})
 same => n,Set(QUEUE_NAME=${ODBC_GET_OPERATOR_QUEUE(${OP_NUM},${TENANT_ID})})
 same => n,Set(RESULT=${ODBC_REMOVE_QUEUE_MEMBER(${INTERFACE_NAME},${TENANT_ID})})
 same => n,System(asterisk -rx "queue show ${QUEUE_NAME}" > /dev/null 2>&1)
 same => n,RemoveQueueMember(${QUEUE_NAME},${INTERFACE_NAME})
 same => n,Set(LOG_ID=${ODBC_LOG_QUEUE_ACTION(${OP_NUM},${INTERFACE_NAME},${QUEUE_NAME},logout,${TENANT_ID})})
 same => n,NoOp(Logged queue logout: operator=${OP_NUM} queue=${QUEUE_NAME} tenant=${TENANT_ID} log_id=${LOG_ID})
 same => n,GoSub(play-localized,s,1(callbox-logout-success))
 same => n,Hangup()
exten => fail_not_registered,1,NoOp(Ошибка: Терминал ${CURRENT_DEVICE} не зарегистрирован ни в одной очереди)
 same => n,GoSub(play-localized,s,1(callbox-invalid-input))
 same => n,Hangup()
#include extensions_trunk.conf
[1001-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
[1002-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
[102-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
include => outbound-calls
[111-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
[998-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
#include extensions_sipp.conf
[101-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
include => outbound-calls
[555-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
[125-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
include => outbound-calls
[135-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
include => outbound-calls
[999-context]
include => hotline
include => internal-calls
include => queue-logic
include => queue-pause-toggle
include => callbox-select-language
include => outbound-calls
[hotline]
exten => 000,1,NoOp(=== Hotline call from ${CHANNEL(endpoint)} ===)
 same => n,Set(HOTLINE_QUEUE=${ODBC_GET_HOTLINE_QUEUE()})
 same => n,GotoIf($["${HOTLINE_QUEUE}" = ""]?hotline_not_configured,1)
 same => n,NoOp(Hotline queue: ${HOTLINE_QUEUE})
 same => n,Set(TENANT_ID=${ODBC_GET_QUEUE_TENANT(${HOTLINE_QUEUE})})
 same => n,NoOp(Hotline tenant_id: ${TENANT_ID})
 same => n,Set(GREETING=${ODBC_GET_ROUTE_GREETING(${HOTLINE_QUEUE})})
 same => n,NoOp(Hotline greeting: ${GREETING})
 same => n,Answer()
 same => n,GotoIf($["${GREETING}" = ""]?hotline_skip_greeting,1)
 same => n,Playback(${GREETING})
 same => n(to_queue),Gosub(cdr-init,s,1(${HOTLINE_QUEUE},${TENANT_ID},000))
 same => n,Set(__CDR_QUEUE_START_EPOCH=${EPOCH})
 same => n,Queue(${HOTLINE_QUEUE},tT,,,300,,,cdr-agent-answer)
 same => n,Hangup()
exten => hotline_skip_greeting,1,NoOp(No greeting for hotline, going to queue)
 same => n,Goto(000,to_queue)
exten => hotline_not_configured,1,NoOp(Hotline not configured)
 same => n,Answer()
 same => n,Playback(callbox/system/callbox-invalid-input)
 same => n,Hangup()
exten => h,1,NoOp(=== Hotline call ended ===)
 same => n,Gosub(cdr-log-answered,s,1)
 same => n,Gosub(cdr-log-direct,s,1)
[text-machine]
exten => _.,1,NoOp(--- KMIS Notification ${RequestID} ---)
 same => n,Answer()
 same => n,Set(CDR_START_EPOCH=${EPOCH})
 same => n,Set(CDR_CALL_DATE=${STRFTIME(${EPOCH},,%Y-%m-%d)})
 same => n,Set(CDR_CALL_TIME=${STRFTIME(${EPOCH},,%H:%M:%S)})
 same => n,Set(CDR_REQUEST_ID=${RequestID})
 same => n,Set(CDR_TENANT_ID=${ODBC_GET_TENANT_BY_REQUEST(${RequestID})})
 same => n,NoOp(Organization ID: ${CDR_TENANT_ID})
 same => n,Set(CDR(userfield)=${RequestID})
 same => n,Wait(1)
 same => n,AGI(/opt/kmis/agi_scripts/kmis.py,${RequestID})
 same => n,Wait(1)
 same => n,GoSub(cdr-log-tts,s,1)
 same => n,Hangup()
exten => h,1,NoOp(--- Hangup TTS call ---)
[cdr-log-tts]
exten => s,1,NoOp(=== Log TTS Call to CDR ===)
 same => n,Set(DURATION=$[${EPOCH} - ${CDR_START_EPOCH}])
 same => n,Set(CALL_TIMESTAMP=${STRFTIME(${CDR_START_EPOCH},,%Y-%m-%d %H:%M:%S)})
 same => n,Set(STATUS=answered)
 same => n,Set(BILLSEC=${IF($[${DURATION} > 0]?${DURATION}:0)})
 same => n,Set(RESULT=${ODBC_LOG_TTS_CALL(${UNIQUEID},${LINKEDID},${CALL_TIMESTAMP},${CDR_CALL_DATE},${CDR_CALL_TIME},${CALLERID(num)},${EXTEN},${STATUS},${DURATION},${BILLSEC},${CDR_TENANT_ID},${CDR_REQUEST_ID})})
 same => n,NoOp(TTS CDR logged: id=${RESULT}, request=${CDR_REQUEST_ID}, org=${CDR_TENANT_ID})
 same => n,Return()