weni-cli 3.9.0__tar.gz → 3.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {weni_cli-3.9.0 → weni_cli-3.10.0}/PKG-INFO +1 -1
- {weni_cli-3.9.0 → weni_cli-3.10.0}/pyproject.toml +1 -1
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/cli.py +72 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/cli_client.py +58 -2
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/tests/test_cli_client.py +126 -0
- weni_cli-3.10.0/weni_cli/commands/channel_delete.py +38 -0
- weni_cli-3.10.0/weni_cli/commands/channel_get.py +63 -0
- weni_cli-3.10.0/weni_cli/commands/channel_list.py +52 -0
- weni_cli-3.10.0/weni_cli/commands/channel_update.py +57 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/README.md +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/auth.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/common.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/response_handlers/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/response_handlers/handlers.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/tests/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/tests/test_weni_client.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/clients/weni_client.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/channel_create.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/eval_init.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/eval_run.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/init.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/login.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/logs.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/project_current.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/project_list.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/project_push.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/project_use.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/run.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/ticketer_create.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/ticketer_delete.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/ticketer_get.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/ticketer_list.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/commands/ticketer_update.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/formatter/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/formatter/formatter.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/formatter/tests/test_formatter.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/handler.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/packager/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/packager/loader.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/packager/packager.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/packager/tests/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/packager/tests/test_loader.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/packager/tests/test_packager.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/spinner/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/spinner/spinners.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/store.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/utils.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/agent_definition.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/channel_definition.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/source.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/tests/__init__.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/tests/conftest.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/tests/test_active_test_definition.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/tests/test_channel_definition.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/tests/test_definition.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/tests/test_source.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/tests/test_ticketer_definition.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/validators/ticketer_definition.py +0 -0
- {weni_cli-3.9.0 → weni_cli-3.10.0}/weni_cli/wsgi.py +0 -0
|
@@ -160,6 +160,78 @@ def create_channel(channel_definition):
|
|
|
160
160
|
click.echo(f"Error: {e}")
|
|
161
161
|
|
|
162
162
|
|
|
163
|
+
@channel.command("list")
|
|
164
|
+
@click.option("--type", "-t", "channel_type", help="Filter by channel type (e.g. WAC, WWC)", type=str)
|
|
165
|
+
@click.option("--exclude-wpp-demo", is_flag=True, help="Hide the WhatsApp demo channel")
|
|
166
|
+
def list_channels(channel_type, exclude_wpp_demo):
|
|
167
|
+
"""List channels of the current project"""
|
|
168
|
+
from weni_cli.commands.channel_list import ChannelListHandler
|
|
169
|
+
|
|
170
|
+
try:
|
|
171
|
+
ChannelListHandler().execute(channel_type=channel_type, exclude_wpp_demo=exclude_wpp_demo)
|
|
172
|
+
except Exception as e:
|
|
173
|
+
click.echo(f"Error: {e}")
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@channel.command("get")
|
|
177
|
+
@click.argument("channel_uuid", required=True, type=click.UUID)
|
|
178
|
+
@click.option("--show-secrets", is_flag=True, help="Show config values that look like tokens, secrets or keys")
|
|
179
|
+
def get_channel(channel_uuid, show_secrets):
|
|
180
|
+
"""Show the details of a channel
|
|
181
|
+
|
|
182
|
+
CHANNEL_UUID: The UUID of the channel
|
|
183
|
+
"""
|
|
184
|
+
from weni_cli.commands.channel_get import ChannelGetHandler
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
ChannelGetHandler().execute(channel_uuid=channel_uuid, show_secrets=show_secrets)
|
|
188
|
+
except Exception as e:
|
|
189
|
+
click.echo(f"Error: {e}")
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@channel.command("update")
|
|
193
|
+
@click.argument("channel_uuid", required=True, type=click.UUID)
|
|
194
|
+
@click.option("--name", "-n", help="New channel name", type=str)
|
|
195
|
+
@click.option("--address", "-a", help="New channel address", type=str)
|
|
196
|
+
@click.option(
|
|
197
|
+
"--config-file",
|
|
198
|
+
"-c",
|
|
199
|
+
help="YAML/JSON file with config keys to merge into the channel config",
|
|
200
|
+
type=click.Path(exists=True, dir_okay=False),
|
|
201
|
+
)
|
|
202
|
+
def update_channel(channel_uuid, name, address, config_file):
|
|
203
|
+
"""Update the name, address or config of a channel
|
|
204
|
+
|
|
205
|
+
CHANNEL_UUID: The UUID of the channel
|
|
206
|
+
|
|
207
|
+
Config keys from --config-file are merged into the current config; keys not in the file stay unchanged.
|
|
208
|
+
"""
|
|
209
|
+
from weni_cli.commands.channel_update import ChannelUpdateHandler
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
ChannelUpdateHandler().execute(
|
|
213
|
+
channel_uuid=channel_uuid, name=name, address=address, config_file=config_file
|
|
214
|
+
)
|
|
215
|
+
except Exception as e:
|
|
216
|
+
click.echo(f"Error: {e}")
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
@channel.command("delete")
|
|
220
|
+
@click.argument("channel_uuid", required=True, type=click.UUID)
|
|
221
|
+
@click.option("--yes", "-y", is_flag=True, help="Skip confirmation")
|
|
222
|
+
def delete_channel(channel_uuid, yes):
|
|
223
|
+
"""Deactivate a channel (soft delete)
|
|
224
|
+
|
|
225
|
+
CHANNEL_UUID: The UUID of the channel
|
|
226
|
+
"""
|
|
227
|
+
from weni_cli.commands.channel_delete import ChannelDeleteHandler
|
|
228
|
+
|
|
229
|
+
try:
|
|
230
|
+
ChannelDeleteHandler().execute(channel_uuid=channel_uuid, yes=yes)
|
|
231
|
+
except Exception as e:
|
|
232
|
+
click.echo(f"Error: {e}")
|
|
233
|
+
|
|
234
|
+
|
|
163
235
|
@cli.group()
|
|
164
236
|
def ticketer():
|
|
165
237
|
"""Ticketer management commands"""
|
|
@@ -164,9 +164,12 @@ class CLIClient:
|
|
|
164
164
|
raise RequestError("Invalid authentication token. Please login again using 'weni login'")
|
|
165
165
|
try:
|
|
166
166
|
error_data = response.json()
|
|
167
|
-
message = error_data.get(
|
|
167
|
+
message = error_data.get(
|
|
168
|
+
"message",
|
|
169
|
+
error_data.get("detail", f"Request failed with status code {response.status_code}"),
|
|
170
|
+
)
|
|
168
171
|
raise RequestError(
|
|
169
|
-
message=message,
|
|
172
|
+
message=str(message),
|
|
170
173
|
status_code=response.status_code,
|
|
171
174
|
data=error_data.get("data"),
|
|
172
175
|
request_id=error_data.get("request_id"),
|
|
@@ -383,6 +386,59 @@ class CLIClient:
|
|
|
383
386
|
except RequestError as e:
|
|
384
387
|
raise RequestError(f"Failed to create channel: {e.message}")
|
|
385
388
|
|
|
389
|
+
def list_channels(self, channel_type: Optional[str] = None, exclude_wpp_demo: bool = False) -> List[Dict[str, Any]]:
|
|
390
|
+
"""List channels of the current project."""
|
|
391
|
+
params: Dict[str, Any] = {}
|
|
392
|
+
if channel_type:
|
|
393
|
+
params["channel_type"] = channel_type
|
|
394
|
+
if exclude_wpp_demo:
|
|
395
|
+
params["exclude_wpp_demo"] = "true"
|
|
396
|
+
|
|
397
|
+
try:
|
|
398
|
+
response = self._make_request(method="GET", endpoint="api/v1/channels", params=params or None)
|
|
399
|
+
return response.json()
|
|
400
|
+
except RequestError as e:
|
|
401
|
+
raise RequestError(f"Failed to list channels: {e.message}")
|
|
402
|
+
|
|
403
|
+
def get_channel(self, channel_uuid: str) -> Dict[str, Any]:
|
|
404
|
+
"""Get one channel of the current project."""
|
|
405
|
+
try:
|
|
406
|
+
response = self._make_request(method="GET", endpoint=f"api/v1/channels/{channel_uuid}")
|
|
407
|
+
return response.json()
|
|
408
|
+
except RequestError as e:
|
|
409
|
+
raise RequestError(f"Failed to get channel: {e.message}")
|
|
410
|
+
|
|
411
|
+
def update_channel(
|
|
412
|
+
self,
|
|
413
|
+
channel_uuid: str,
|
|
414
|
+
name: Optional[str] = None,
|
|
415
|
+
address: Optional[str] = None,
|
|
416
|
+
config: Optional[Dict[str, Any]] = None,
|
|
417
|
+
) -> Dict[str, Any]:
|
|
418
|
+
"""Partially update a channel. The backend merges config into the stored one."""
|
|
419
|
+
payload: Dict[str, Any] = {}
|
|
420
|
+
if name is not None:
|
|
421
|
+
payload["name"] = name
|
|
422
|
+
if address is not None:
|
|
423
|
+
payload["address"] = address
|
|
424
|
+
if config is not None:
|
|
425
|
+
payload["config"] = config
|
|
426
|
+
|
|
427
|
+
try:
|
|
428
|
+
response = self._make_request(
|
|
429
|
+
method="PATCH", endpoint=f"api/v1/channels/{channel_uuid}", json_data=payload
|
|
430
|
+
)
|
|
431
|
+
return response.json()
|
|
432
|
+
except RequestError as e:
|
|
433
|
+
raise RequestError(f"Failed to update channel: {e.message}")
|
|
434
|
+
|
|
435
|
+
def delete_channel(self, channel_uuid: str) -> None:
|
|
436
|
+
"""Soft-delete a channel (Flows sets is_active to false)."""
|
|
437
|
+
try:
|
|
438
|
+
self._make_request(method="DELETE", endpoint=f"api/v1/channels/{channel_uuid}")
|
|
439
|
+
except RequestError as e:
|
|
440
|
+
raise RequestError(f"Failed to delete channel: {e.message}")
|
|
441
|
+
|
|
386
442
|
def create_ticketer(self, project_uuid: str, ticketer_definition: Dict) -> Dict[str, Any]:
|
|
387
443
|
"""Create a ticketer."""
|
|
388
444
|
if "ticketers" not in ticketer_definition or not ticketer_definition["ticketers"]:
|
|
@@ -1427,3 +1427,129 @@ def test_create_ticketer_request_error(client, mocker):
|
|
|
1427
1427
|
|
|
1428
1428
|
assert "Failed to create ticketer" in str(exc_info.value)
|
|
1429
1429
|
assert error_message in str(exc_info.value)
|
|
1430
|
+
|
|
1431
|
+
|
|
1432
|
+
def test_make_request_uses_detail_when_message_is_missing(client, mocker):
|
|
1433
|
+
"""FastAPI HTTPException bodies only carry 'detail'."""
|
|
1434
|
+
error_resp = mocker.MagicMock()
|
|
1435
|
+
error_resp.status_code = 404
|
|
1436
|
+
error_resp.json.return_value = {"detail": "Channel not found"}
|
|
1437
|
+
client.session.request = mocker.MagicMock(return_value=error_resp)
|
|
1438
|
+
|
|
1439
|
+
with pytest.raises(RequestError) as excinfo:
|
|
1440
|
+
client._make_request("GET", "api/v1/channels/some-uuid")
|
|
1441
|
+
|
|
1442
|
+
assert excinfo.value.message == "Channel not found"
|
|
1443
|
+
assert excinfo.value.status_code == 404
|
|
1444
|
+
|
|
1445
|
+
|
|
1446
|
+
def test_list_channels_success(client, mocker):
|
|
1447
|
+
mock_response = mocker.MagicMock()
|
|
1448
|
+
mock_response.json.return_value = [{"uuid": "channel-uuid", "name": "Test Channel"}]
|
|
1449
|
+
mocker.patch.object(client, "_make_request", return_value=mock_response)
|
|
1450
|
+
|
|
1451
|
+
result = client.list_channels(channel_type="WAC", exclude_wpp_demo=True)
|
|
1452
|
+
|
|
1453
|
+
assert result == [{"uuid": "channel-uuid", "name": "Test Channel"}]
|
|
1454
|
+
client._make_request.assert_called_once_with(
|
|
1455
|
+
method="GET",
|
|
1456
|
+
endpoint="api/v1/channels",
|
|
1457
|
+
params={"channel_type": "WAC", "exclude_wpp_demo": "true"},
|
|
1458
|
+
)
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
def test_list_channels_without_filters_sends_no_params(client, mocker):
|
|
1462
|
+
mock_response = mocker.MagicMock()
|
|
1463
|
+
mock_response.json.return_value = []
|
|
1464
|
+
mocker.patch.object(client, "_make_request", return_value=mock_response)
|
|
1465
|
+
|
|
1466
|
+
client.list_channels()
|
|
1467
|
+
|
|
1468
|
+
client._make_request.assert_called_once_with(method="GET", endpoint="api/v1/channels", params=None)
|
|
1469
|
+
|
|
1470
|
+
|
|
1471
|
+
def test_list_channels_request_error(client, mocker):
|
|
1472
|
+
mocker.patch.object(client, "_make_request", side_effect=RequestError(message="Forbidden", status_code=403))
|
|
1473
|
+
|
|
1474
|
+
with pytest.raises(RequestError) as exc_info:
|
|
1475
|
+
client.list_channels()
|
|
1476
|
+
|
|
1477
|
+
assert "Failed to list channels: Forbidden" in str(exc_info.value)
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
def test_get_channel_success(client, mocker):
|
|
1481
|
+
mock_response = mocker.MagicMock()
|
|
1482
|
+
mock_response.json.return_value = {"uuid": "channel-uuid"}
|
|
1483
|
+
mocker.patch.object(client, "_make_request", return_value=mock_response)
|
|
1484
|
+
|
|
1485
|
+
result = client.get_channel("channel-uuid")
|
|
1486
|
+
|
|
1487
|
+
assert result == {"uuid": "channel-uuid"}
|
|
1488
|
+
client._make_request.assert_called_once_with(method="GET", endpoint="api/v1/channels/channel-uuid")
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
def test_get_channel_request_error(client, mocker):
|
|
1492
|
+
mocker.patch.object(
|
|
1493
|
+
client, "_make_request", side_effect=RequestError(message="Channel not found", status_code=404)
|
|
1494
|
+
)
|
|
1495
|
+
|
|
1496
|
+
with pytest.raises(RequestError) as exc_info:
|
|
1497
|
+
client.get_channel("channel-uuid")
|
|
1498
|
+
|
|
1499
|
+
assert "Failed to get channel: Channel not found" in str(exc_info.value)
|
|
1500
|
+
|
|
1501
|
+
|
|
1502
|
+
def test_update_channel_sends_only_given_fields(client, mocker):
|
|
1503
|
+
mock_response = mocker.MagicMock()
|
|
1504
|
+
mock_response.json.return_value = {"uuid": "channel-uuid", "name": "Renamed"}
|
|
1505
|
+
mocker.patch.object(client, "_make_request", return_value=mock_response)
|
|
1506
|
+
|
|
1507
|
+
result = client.update_channel("channel-uuid", name="Renamed", config={"extra": "1"})
|
|
1508
|
+
|
|
1509
|
+
assert result == {"uuid": "channel-uuid", "name": "Renamed"}
|
|
1510
|
+
client._make_request.assert_called_once_with(
|
|
1511
|
+
method="PATCH",
|
|
1512
|
+
endpoint="api/v1/channels/channel-uuid",
|
|
1513
|
+
json_data={"name": "Renamed", "config": {"extra": "1"}},
|
|
1514
|
+
)
|
|
1515
|
+
|
|
1516
|
+
|
|
1517
|
+
def test_update_channel_sends_address_only(client, mocker):
|
|
1518
|
+
mock_response = mocker.MagicMock()
|
|
1519
|
+
mock_response.json.return_value = {"uuid": "channel-uuid"}
|
|
1520
|
+
mocker.patch.object(client, "_make_request", return_value=mock_response)
|
|
1521
|
+
|
|
1522
|
+
client.update_channel("channel-uuid", address="+5511999999999")
|
|
1523
|
+
|
|
1524
|
+
client._make_request.assert_called_once_with(
|
|
1525
|
+
method="PATCH",
|
|
1526
|
+
endpoint="api/v1/channels/channel-uuid",
|
|
1527
|
+
json_data={"address": "+5511999999999"},
|
|
1528
|
+
)
|
|
1529
|
+
|
|
1530
|
+
|
|
1531
|
+
def test_update_channel_request_error(client, mocker):
|
|
1532
|
+
mocker.patch.object(client, "_make_request", side_effect=RequestError(message="Invalid", status_code=400))
|
|
1533
|
+
|
|
1534
|
+
with pytest.raises(RequestError) as exc_info:
|
|
1535
|
+
client.update_channel("channel-uuid", name="Renamed")
|
|
1536
|
+
|
|
1537
|
+
assert "Failed to update channel: Invalid" in str(exc_info.value)
|
|
1538
|
+
|
|
1539
|
+
|
|
1540
|
+
def test_delete_channel_success(client, mocker):
|
|
1541
|
+
mocker.patch.object(client, "_make_request", return_value=mocker.MagicMock())
|
|
1542
|
+
|
|
1543
|
+
assert client.delete_channel("channel-uuid") is None
|
|
1544
|
+
client._make_request.assert_called_once_with(method="DELETE", endpoint="api/v1/channels/channel-uuid")
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
def test_delete_channel_request_error(client, mocker):
|
|
1548
|
+
mocker.patch.object(
|
|
1549
|
+
client, "_make_request", side_effect=RequestError(message="Channel not found", status_code=404)
|
|
1550
|
+
)
|
|
1551
|
+
|
|
1552
|
+
with pytest.raises(RequestError) as exc_info:
|
|
1553
|
+
client.delete_channel("channel-uuid")
|
|
1554
|
+
|
|
1555
|
+
assert "Failed to delete channel: Channel not found" in str(exc_info.value)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import rich_click as click
|
|
2
|
+
|
|
3
|
+
from weni_cli.clients.cli_client import CLIClient
|
|
4
|
+
from weni_cli.formatter.formatter import Formatter
|
|
5
|
+
from weni_cli.handler import Handler
|
|
6
|
+
from weni_cli.spinner import spinner
|
|
7
|
+
from weni_cli.store import STORE_PROJECT_UUID_KEY, Store
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ChannelDeleteHandler(Handler):
|
|
11
|
+
def execute(self, **kwargs):
|
|
12
|
+
channel_uuid = kwargs.get("channel_uuid")
|
|
13
|
+
skip_confirmation = kwargs.get("yes", False)
|
|
14
|
+
|
|
15
|
+
formatter = Formatter()
|
|
16
|
+
|
|
17
|
+
if not channel_uuid:
|
|
18
|
+
formatter.print_error_panel("Channel UUID is required")
|
|
19
|
+
return
|
|
20
|
+
|
|
21
|
+
store = Store()
|
|
22
|
+
project_uuid = store.get(STORE_PROJECT_UUID_KEY)
|
|
23
|
+
|
|
24
|
+
if not project_uuid:
|
|
25
|
+
formatter.print_error_panel("No project selected, please select a project first")
|
|
26
|
+
return
|
|
27
|
+
|
|
28
|
+
if not skip_confirmation and not click.confirm(
|
|
29
|
+
f"Deactivate channel {channel_uuid}? It will stop sending and receiving messages", default=False
|
|
30
|
+
):
|
|
31
|
+
formatter.print_warning_panel("Channel deletion cancelled")
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
client = CLIClient()
|
|
35
|
+
with spinner():
|
|
36
|
+
client.delete_channel(str(channel_uuid))
|
|
37
|
+
|
|
38
|
+
formatter.print_success_panel(f"Channel deactivated successfully\nUUID: {channel_uuid}")
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
from weni_cli.clients.cli_client import CLIClient
|
|
4
|
+
from weni_cli.formatter.formatter import Formatter
|
|
5
|
+
from weni_cli.handler import Handler
|
|
6
|
+
from weni_cli.spinner import spinner
|
|
7
|
+
from weni_cli.store import STORE_PROJECT_UUID_KEY, Store
|
|
8
|
+
|
|
9
|
+
SECRET_KEY_MARKERS = ("token", "secret", "password", "key")
|
|
10
|
+
MASKED_VALUE = "****"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def mask_secrets(value):
|
|
14
|
+
if isinstance(value, dict):
|
|
15
|
+
return {
|
|
16
|
+
key: MASKED_VALUE
|
|
17
|
+
if any(marker in str(key).lower() for marker in SECRET_KEY_MARKERS)
|
|
18
|
+
else mask_secrets(item)
|
|
19
|
+
for key, item in value.items()
|
|
20
|
+
}
|
|
21
|
+
if isinstance(value, list):
|
|
22
|
+
return [mask_secrets(item) for item in value]
|
|
23
|
+
return value
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ChannelGetHandler(Handler):
|
|
27
|
+
def execute(self, **kwargs):
|
|
28
|
+
channel_uuid = kwargs.get("channel_uuid")
|
|
29
|
+
show_secrets = kwargs.get("show_secrets", False)
|
|
30
|
+
|
|
31
|
+
formatter = Formatter()
|
|
32
|
+
|
|
33
|
+
if not channel_uuid:
|
|
34
|
+
formatter.print_error_panel("Channel UUID is required")
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
store = Store()
|
|
38
|
+
project_uuid = store.get(STORE_PROJECT_UUID_KEY)
|
|
39
|
+
|
|
40
|
+
if not project_uuid:
|
|
41
|
+
formatter.print_error_panel("No project selected, please select a project first")
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
client = CLIClient()
|
|
45
|
+
with spinner():
|
|
46
|
+
channel = client.get_channel(str(channel_uuid))
|
|
47
|
+
|
|
48
|
+
config = channel.get("config") or {}
|
|
49
|
+
if not show_secrets:
|
|
50
|
+
config = mask_secrets(config)
|
|
51
|
+
|
|
52
|
+
details = [
|
|
53
|
+
f"UUID: {channel.get('uuid', '')}",
|
|
54
|
+
f"Name: {channel.get('name', '')}",
|
|
55
|
+
f"Type: {channel.get('channel_type', '')}",
|
|
56
|
+
f"Address: {channel.get('address') or ''}",
|
|
57
|
+
f"Active: {'yes' if channel.get('is_active') else 'no'}",
|
|
58
|
+
f"Project: {channel.get('org') or ''}",
|
|
59
|
+
"Config:",
|
|
60
|
+
json.dumps(config, indent=2, ensure_ascii=False),
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
formatter.print_success_panel("\n".join(details))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.table import Table
|
|
3
|
+
|
|
4
|
+
from weni_cli.clients.cli_client import CLIClient
|
|
5
|
+
from weni_cli.formatter.formatter import Formatter
|
|
6
|
+
from weni_cli.handler import Handler
|
|
7
|
+
from weni_cli.spinner import spinner
|
|
8
|
+
from weni_cli.store import STORE_PROJECT_UUID_KEY, Store
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ChannelListHandler(Handler):
|
|
12
|
+
def execute(self, **kwargs):
|
|
13
|
+
channel_type = kwargs.get("channel_type")
|
|
14
|
+
exclude_wpp_demo = kwargs.get("exclude_wpp_demo", False)
|
|
15
|
+
|
|
16
|
+
formatter = Formatter()
|
|
17
|
+
|
|
18
|
+
store = Store()
|
|
19
|
+
project_uuid = store.get(STORE_PROJECT_UUID_KEY)
|
|
20
|
+
|
|
21
|
+
if not project_uuid:
|
|
22
|
+
formatter.print_error_panel("No project selected, please select a project first")
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
client = CLIClient()
|
|
26
|
+
with spinner():
|
|
27
|
+
channels = client.list_channels(channel_type=channel_type, exclude_wpp_demo=exclude_wpp_demo)
|
|
28
|
+
|
|
29
|
+
if not channels:
|
|
30
|
+
formatter.print_warning_panel("No channels found for this project")
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
Console().print(self._build_table(channels))
|
|
34
|
+
|
|
35
|
+
def _build_table(self, channels):
|
|
36
|
+
table = Table(title="Channels", expand=True)
|
|
37
|
+
table.add_column("UUID", justify="left", no_wrap=True)
|
|
38
|
+
table.add_column("Name", justify="left")
|
|
39
|
+
table.add_column("Type", justify="center")
|
|
40
|
+
table.add_column("Address", justify="left")
|
|
41
|
+
table.add_column("Active", justify="center")
|
|
42
|
+
|
|
43
|
+
for channel in channels:
|
|
44
|
+
table.add_row(
|
|
45
|
+
str(channel.get("uuid") or ""),
|
|
46
|
+
str(channel.get("name") or ""),
|
|
47
|
+
str(channel.get("channel_type") or ""),
|
|
48
|
+
str(channel.get("address") or ""),
|
|
49
|
+
"yes" if channel.get("is_active") else "no",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
return table
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from weni_cli.clients.cli_client import CLIClient
|
|
2
|
+
from weni_cli.formatter.formatter import Formatter
|
|
3
|
+
from weni_cli.handler import Handler
|
|
4
|
+
from weni_cli.spinner import spinner
|
|
5
|
+
from weni_cli.store import STORE_PROJECT_UUID_KEY, Store
|
|
6
|
+
from weni_cli.validators.channel_definition import load_yaml_file
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ChannelUpdateHandler(Handler):
|
|
10
|
+
def execute(self, **kwargs):
|
|
11
|
+
channel_uuid = kwargs.get("channel_uuid")
|
|
12
|
+
name = kwargs.get("name")
|
|
13
|
+
address = kwargs.get("address")
|
|
14
|
+
config_file = kwargs.get("config_file")
|
|
15
|
+
|
|
16
|
+
formatter = Formatter()
|
|
17
|
+
|
|
18
|
+
if not channel_uuid:
|
|
19
|
+
formatter.print_error_panel("Channel UUID is required")
|
|
20
|
+
return
|
|
21
|
+
|
|
22
|
+
if name is None and address is None and not config_file:
|
|
23
|
+
formatter.print_error_panel("Provide at least one of --name, --address or --config-file")
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
store = Store()
|
|
27
|
+
project_uuid = store.get(STORE_PROJECT_UUID_KEY)
|
|
28
|
+
|
|
29
|
+
if not project_uuid:
|
|
30
|
+
formatter.print_error_panel("No project selected, please select a project first")
|
|
31
|
+
return
|
|
32
|
+
|
|
33
|
+
config = None
|
|
34
|
+
if config_file:
|
|
35
|
+
config, error = load_yaml_file(config_file)
|
|
36
|
+
if error:
|
|
37
|
+
formatter.print_error_panel(f"Could not read config file: {error}")
|
|
38
|
+
return
|
|
39
|
+
if not isinstance(config, dict) or not config:
|
|
40
|
+
formatter.print_error_panel("Config file must contain a non-empty key/value mapping")
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
client = CLIClient()
|
|
44
|
+
with spinner():
|
|
45
|
+
response = client.update_channel(str(channel_uuid), name=name, address=address, config=config)
|
|
46
|
+
|
|
47
|
+
details = []
|
|
48
|
+
if isinstance(response, dict):
|
|
49
|
+
if response.get("name"):
|
|
50
|
+
details.append(f"Name: {response['name']}")
|
|
51
|
+
if response.get("uuid"):
|
|
52
|
+
details.append(f"UUID: {response['uuid']}")
|
|
53
|
+
|
|
54
|
+
if details:
|
|
55
|
+
formatter.print_success_panel("Channel updated successfully\n" + "\n".join(details))
|
|
56
|
+
else:
|
|
57
|
+
formatter.print_success_panel("Channel updated successfully")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|