# Asterisk Lab Config

This folder contains the lab-grade configuration set for Track 9, Track 11, and Track 14:

- `pjsip.conf`
- `extensions.conf`
- `manager.conf`
- `http.conf`
- `rtp.conf`

These files are templates for a dedicated Linux VM running Asterisk 20 LTS.

Before using them:

1. Replace default passwords and secrets.
2. Confirm the softphone source network.
3. Create the recording directory:
   - `/var/spool/asterisk/monitor/mvpcc`
4. Point `ASTERISK_QUEUE_MAP_JSON` in the platform to the matching queue code:
   - `voice_lab`
   - `voice_lab_ai` for the dedicated AI-first staging entrypoint
   - `voice_lab_ivr` for the dedicated IVR staging entrypoint
5. Configure operator extension mapping in bridge env for Track 11 call control:
   - `ASTERISK_OPERATOR_EXTENSION_MAP_JSON={"operator_a":"2001","operator_b":"2002"}`
6. Optional transfer map for queue-code based blind transfer:
   - `ASTERISK_TRANSFER_TARGET_MAP_JSON={"voice_lab":"2001","voice_lab_ai":"2001","voice_lab_ivr":"7200"}`
7. For IVR-over-Asterisk staging:
   - enable `ASTERISK_IVR_FASTAGI_ENABLED=1`
   - set `ASTERISK_IVR_FASTAGI_HOST=<bridge-host>`
   - set `ASTERISK_IVR_FASTAGI_PORT=4573`
   - set `IVR_RUNTIME_TRUSTED_SERVICE_SUBJECTS=svc:asterisk-bridge`
   - provision the referenced `prompt_audio_key` files under the Asterisk sounds directory
   - if you want a higher-quality prompt from OpenAI TTS, generate it once and keep it on the server:
     - `python scripts/materialize_tts_prompt.py --text "Здравствуйте! Добро пожаловать в контакт-центр. Для русского языка нажмите 1. Қазақ тілі үшін 2 басыңыз." --output /usr/share/asterisk/sounds/en/mvpcc_ivr_language.wav --language ru`
     - `python scripts/materialize_tts_prompt.py --text "Для отдела продаж нажмите 1. Для службы поддержки нажмите 2." --output /usr/share/asterisk/sounds/en/mvpcc_ivr_menu_ru.wav --language ru`
     - `python scripts/materialize_tts_prompt.py --text "Сату бөлімі үшін 1 басыңыз. Қолдау қызметі үшін 2 басыңыз." --output /usr/share/asterisk/sounds/en/mvpcc_ivr_menu_kz.wav --language kk`
     - repeated runs reuse the server cache from `AI_VOICE_TTS_CACHE_DIR` instead of calling OpenAI again for the same text
8. For Track 14 browser softphone QA:
   - enable `ASTERISK_WEBRTC_ENABLED=1`
   - set `ASTERISK_WEBRTC_WS_URL=wss://<asterisk-host>:8089/ws`
   - configure `ASTERISK_BROWSER_SIP_MAP_JSON`
   - replace TLS placeholders in `http.conf` with a trusted cert/key pair
9. For Voice AI V1 lab wiring:
   - enable `AI_VOICE_ENABLED=1`
   - set `AI_VOICE_QUEUE_CONFIG_JSON={"voice_lab_ai":{"mode":"ai_first","agent_profile":"voice_support","handoff_queue_code":"voice_lab","language":"ru"}}`
   - set `AI_VOICE_RUNTIME_SERVICE_URL=http://ai-voice-runtime-service:8000`
   - keep `AI_VOICE_RUNTIME_TRUSTED_SERVICE_SUBJECTS=svc:ai-voice-runtime`
   - load `app_audiosocket.so` on the Asterisk VM before enabling the AI media path
   - set `MVPCC_AI_AUDIOSOCKET_SERVICE=<media-host>:<port>` in `extensions.conf` only after the AudioSocket listener is reachable

Entrypoints in `extensions.conf`:

- `7000`: human-only baseline. This path preserves the original Track 9/11 behavior.
- `7100`: AI-first staging path. It emits the normal `MVPCCCallStarted` event with `QueueCode=voice_lab_ai`, then:
  - falls back to human dialing immediately if `MVPCC_AI_AUDIOSOCKET_SERVICE` is blank
  - otherwise starts `AudioSocket(<uuid>,<host>:<port>)` for the media bridge
- `7200`: IVR staging path. It emits the normal `MVPCCCallStarted` event with `QueueCode=voice_lab_ivr`, then:
  - hands control to FastAGI at `MVPCC_IVR_FASTAGI_HOSTPORT`
  - routes completed IVR sessions through `mvpcc-transfer`
  - falls back to the human baseline if FastAGI does not return a transfer target

Important Voice AI note:

- `AI_VOICE_RUNTIME_SERVICE_URL` is the HTTP control-plane endpoint for platform services.
- `MVPCC_AI_AUDIOSOCKET_SERVICE` is a separate raw AudioSocket address for Asterisk media.
- Do not point `MVPCC_AI_AUDIOSOCKET_SERVICE` at the runtime HTTP port.

Default lab SIP accounts from `pjsip.conf`:
- `1001` (caller)
- `2001` (operator A)
- `2002` (operator B)

Telecom.kz note:
- `87273901485 / 86205414@sip.telecom.kz` should be configured as a normal SIP account with `type=registration`.
- Do not treat this number as an IP trunk unless Telecom provisions a separate IP-trunk product for it.
- Inbound calls from this account are expected in `from-telecom` and should route to `7100`.
- Keep the real Telecom password out of git and set it on the target host before reload.

Track 14 note:
- `2001` and `2002` are allowed to keep multiple contacts so browser registration can coexist with `MicroSIP/Zoiper` in QA.
