Uso de GetSmsChannel con un SDK de AWS o la CLI - Amazon Pinpoint

Aviso de fin de soporte: el 30 de octubre de 2026, AWS finalizará el soporte para Amazon Pinpoint. Después del 30 de octubre de 2026, ya no podrá acceder a la consola de Amazon Pinpoint ni a los recursos de Amazon Pinpoint (puntos de conexión, segmentos, campañas, recorridos y análisis). Para obtener más información, consulte Fin de soporte de Amazon Pinpoint. Nota: Este cambio no afecta a las API relacionadas con los SMS, los mensajes de voz, las notificaciones push móviles, la OTP y la validación de números de teléfono, por lo que son compatibles con Mensajería para usuarios finales de AWS.

Uso de GetSmsChannel con un SDK de AWS o la CLI

Los siguientes ejemplos de código muestran cómo utilizar GetSmsChannel.

CLI
AWS CLI

Para recuperar información sobre el estado y la configuración del canal de SMS para una aplicación

En el siguiente ejemplo de get-sms-channel se recupera el estado y la configuración del canal de SMS de una aplicación.

aws pinpoint get-sms-channel \ --application-id 6e0b7591a90841d2b5d93fa11143e5a7 \ --region us-east-1

Salida:

{ "SMSChannelResponse": { "ApplicationId": "6e0b7591a90841d2b5d93fa11143e5a7", "CreationDate": "2019-10-08T18:39:18.511Z", "Enabled": true, "Id": "sms", "IsArchived": false, "LastModifiedDate": "2019-10-08T18:39:18.511Z", "Platform": "SMS", "PromotionalMessagesPerSecond": 20, "TransactionalMessagesPerSecond": 20, "Version": 1 } }
  • Para obtener información sobre la API, consulte GetSmsChannel en la Referencia de comandos de la AWS CLI.

Java
SDK para Java 2.x
nota

Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.SMSChannelResponse; import software.amazon.awssdk.services.pinpoint.model.GetSmsChannelRequest; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import software.amazon.awssdk.services.pinpoint.model.SMSChannelRequest; import software.amazon.awssdk.services.pinpoint.model.UpdateSmsChannelRequest; import software.amazon.awssdk.services.pinpoint.model.UpdateSmsChannelResponse; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class UpdateChannel { public static void main(String[] args) { final String usage = """ Usage: CreateChannel <appId> Where: appId - The name of the application whose channel is updated. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String appId = args[0]; PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); SMSChannelResponse getResponse = getSMSChannel(pinpoint, appId); toggleSmsChannel(pinpoint, appId, getResponse); pinpoint.close(); } private static SMSChannelResponse getSMSChannel(PinpointClient client, String appId) { try { GetSmsChannelRequest request = GetSmsChannelRequest.builder() .applicationId(appId) .build(); SMSChannelResponse response = client.getSmsChannel(request).smsChannelResponse(); System.out.println("Channel state is " + response.enabled()); return response; } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; } private static void toggleSmsChannel(PinpointClient client, String appId, SMSChannelResponse getResponse) { boolean enabled = !getResponse.enabled(); try { SMSChannelRequest request = SMSChannelRequest.builder() .enabled(enabled) .build(); UpdateSmsChannelRequest updateRequest = UpdateSmsChannelRequest.builder() .smsChannelRequest(request) .applicationId(appId) .build(); UpdateSmsChannelResponse result = client.updateSmsChannel(updateRequest); System.out.println("Channel state: " + result.smsChannelResponse().enabled()); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
  • Para obtener información acerca de la API, consulte GetSmsChannel en la Referencia de la API de AWS SDK for Java 2.x.

Para obtener una lista completa de las guías para desarrolladores de AWS SDK y ejemplos de código, consulte Uso de Amazon Pinpoint con un AWS SDK. En este tema también se incluye información sobre cómo comenzar a utilizar el SDK y detalles sobre sus versiones anteriores.