mirror of
https://github.com/Sea-Haven-Industries/ring-scheduler-3cx.git
synced 2026-05-18 20:20:12 +00:00
Switch from ring group to queue API for extension 801
3CX extension 801 was converted from a ring group to a queue, so the XAPI calls need to use Queues endpoints instead of RingGroups. Also adds samconfig.toml for streamlined deploys.
This commit is contained in:
parent
c2b81a9f6b
commit
77989d1983
4 changed files with 23 additions and 15 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# 3CX office hours: 8am - 5pm (configured in 3CX admin)
|
||||
# This Lambda runs at 8am daily and sets the after-hours destination for that evening.
|
||||
|
||||
ring_group_number: "800" # Your ring group extension number
|
||||
ring_group_number: "801" # Your ring group extension number
|
||||
|
||||
# Default weekly schedule: day -> extension for after-hours (5pm - 8am)
|
||||
# Saturday/Sunday inherit Friday's setting (Ext 116) unless overridden below
|
||||
|
|
|
|||
8
samconfig.toml
Normal file
8
samconfig.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
version = 0.1
|
||||
|
||||
[default.deploy.parameters]
|
||||
stack_name = "ring-scheduler-3cx"
|
||||
resolve_s3 = true
|
||||
capabilities = "CAPABILITY_IAM"
|
||||
region = "us-east-1"
|
||||
confirm_changeset = false
|
||||
|
|
@ -177,11 +177,11 @@ def handler(event, context):
|
|||
client_secret=creds["client_secret"],
|
||||
)
|
||||
|
||||
ring_group = client.get_ring_group(schedule["ring_group_number"])
|
||||
ring_group_id = ring_group["Id"]
|
||||
queue = client.get_queue(schedule["ring_group_number"])
|
||||
queue_id = queue["Id"]
|
||||
|
||||
client.update_ring_group_forwarding(
|
||||
ring_group_id=ring_group_id,
|
||||
client.update_queue_forwarding(
|
||||
queue_id=queue_id,
|
||||
closed_destination=extension,
|
||||
holiday_destination=extension,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -57,24 +57,24 @@ class ThreeCXClient:
|
|||
self.session.headers.update({"Authorization": f"Bearer {token}"})
|
||||
logger.info("Authenticated to 3CX via OAuth2 client credentials")
|
||||
|
||||
def get_ring_group(self, extension_number: str) -> dict:
|
||||
"""Fetch ring group config by extension number."""
|
||||
def get_queue(self, extension_number: str) -> dict:
|
||||
"""Fetch queue config by extension number."""
|
||||
resp = self.session.get(
|
||||
f"{self.base_url}/xapi/v1/RingGroups/Pbx.GetByNumber(number='{extension_number}')",
|
||||
f"{self.base_url}/xapi/v1/Queues/Pbx.GetByNumber(number='{extension_number}')",
|
||||
)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
|
||||
def update_ring_group_forwarding(
|
||||
def update_queue_forwarding(
|
||||
self,
|
||||
ring_group_id: int,
|
||||
queue_id: int,
|
||||
closed_destination: str,
|
||||
holiday_destination: str,
|
||||
):
|
||||
"""Update the OutOfOfficeRoute and HolidaysRoute on a ring group.
|
||||
"""Update the OutOfOfficeRoute and HolidaysRoute on a queue.
|
||||
|
||||
Args:
|
||||
ring_group_id: Numeric ID from the ring group entity
|
||||
queue_id: Numeric ID from the queue entity
|
||||
closed_destination: Extension number for after-hours routing
|
||||
holiday_destination: Extension number for holiday routing
|
||||
"""
|
||||
|
|
@ -97,13 +97,13 @@ class ThreeCXClient:
|
|||
},
|
||||
}
|
||||
resp = self.session.patch(
|
||||
f"{self.base_url}/xapi/v1/RingGroups({ring_group_id})",
|
||||
f"{self.base_url}/xapi/v1/Queues({queue_id})",
|
||||
json=payload,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
logger.info(
|
||||
"Updated ring group %s: closed->Ext %s, holiday->Ext %s",
|
||||
ring_group_id,
|
||||
"Updated queue %s: closed->Ext %s, holiday->Ext %s",
|
||||
queue_id,
|
||||
closed_destination,
|
||||
holiday_destination,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue