Revogar uma mensagem RCS enviada
Neste trecho de código, você aprenderá a enviar um RCS file mensagem usando a Messages API.
- Para obter mais informações sobre o RCS Messaging, consulte Entendendo as mensagens RCS
Exemplo
Veja a seguir a descrição de todas as variáveis utilizadas em cada trecho de código:
| Chave | Descrição |
|---|---|
VONAGE_APPLICATION_ID | The Vonage Application ID. |
VONAGE_PRIVATE_KEY_PATH | Private key path. |
GEOSPECIFIC_MESSAGES_API_URL | The URL for the Geo-specific Messages API endpoint. One of |
GEOSPECIFIC_VONAGE_API_HOST | The hostname for the Geo-specific API endpoint. One of |
JWT | Used to authenticate your request. See |
MESSAGE_UUID | The UUID of the specific message. |
NOTA: O URI base deve ser específico para a localização da mensagem que está sendo revogada.
Pré-requisitos
Se você não tiver um aplicativo, acesse criar um. Certifique-se também de acessar configure seus webhooks.
Escreva o código
Adicione o seguinte ao arquivo ` revoke-message.sh`:
curl -X PATCH "${GEOSPECIFIC_MESSAGES_API_URL}/${MESSAGES_MESSAGE_ID}" \
-H "Authorization: Bearer "$JWT\
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d $'{"status": "revoked"}'Execute seu código
Salve este arquivo no seu computador e execute-o:
Pré-requisitos
Se você não tiver um aplicativo, acesse criar um. Certifique-se também de acessar configure seus webhooks.
npm install @vonage/server-sdkCrie um arquivo chamado ` revoke-message.js ` e insira o seguinte código:
const { Vonage } = require('@vonage/server-sdk');
/**
* It is best to send messages using JWT instead of basic auth. If you leave out
* apiKey and apiSecret, the messages SDK will send requests using JWT tokens
*
* @link https://developer.vonage.com/en/messages/technical-details#authentication
*/
const vonage = new Vonage(
{
applicationId: VONAGE_APPLICATION_ID,
privateKey: VONAGE_PRIVATE_KEY,
},
{
...(MESSAGES_API_URL ? {apiHost: MESSAGES_API_URL} : {}),
},
);Escreva o código
Adicione o seguinte ao arquivo ` revoke-message.js`:
vonage.messages.updateMessage(MESSAGE_ID, 'revoked')
.then(() => console.log('Message revoked'))
.catch((error) => console.error(error));Execute seu código
Salve este arquivo no seu computador e execute-o:
Pré-requisitos
Se você não tiver um aplicativo, acesse criar um. Certifique-se também de acessar configure seus webhooks.
Adicione o seguinte ao arquivo ` build.gradle`:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'Crie um arquivo chamado ` RevokeMessage ` e adicione o código a seguir ao método ` main `:
val client = Vonage {
applicationId(VONAGE_APPLICATION_ID)
privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
}Escreva o código
Adicione o seguinte ao método ` main ` do arquivo ` RevokeMessage `:
client.messages.existingMessage(MESSAGES_MESSAGE_ID, MESSAGES_GEOSPECIFIC_API_HOST).revoke()Execute seu código
Podemos usar o plugin “ aplicativo ” para o Gradle a fim de simplificar a execução do nosso aplicativo. Atualize seu arquivo ` build.gradle ` com o seguinte:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Execute o seguinte comando ` gradle ` para rodar seu aplicativo, substituindo ` com.vonage.quickstart.kt.messages.rcs ` pelo pacote que contém ` RevokeMessage`:
Pré-requisitos
Se você não tiver um aplicativo, acesse criar um. Certifique-se também de acessar configure seus webhooks.
Adicione o seguinte ao arquivo ` build.gradle`:
implementation 'com.vonage:server-sdk:9.3.1'Crie um arquivo chamado ` RevokeMessage ` e adicione o código a seguir ao método ` main `:
VonageClient client = VonageClient.builder()
.applicationId(VONAGE_APPLICATION_ID)
.privateKeyPath(VONAGE_PRIVATE_KEY_PATH)
.build();Escreva o código
Adicione o seguinte ao método ` main ` do arquivo ` RevokeMessage `:
client.getMessagesClient().revokeOutboundMessage(MESSAGES_MESSAGE_ID, MESSAGES_GEOSPECIFIC_API_HOST);Execute seu código
Podemos usar o plugin “ aplicativo ” para o Gradle a fim de simplificar a execução do nosso aplicativo. Atualize seu arquivo ` build.gradle ` com o seguinte:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Execute o seguinte comando ` gradle ` para rodar seu aplicativo, substituindo ` com.vonage.quickstart.messages.rcs ` pelo pacote que contém ` RevokeMessage`:
Pré-requisitos
Se você não tiver um aplicativo, acesse criar um. Certifique-se também de acessar configure seus webhooks.
Install-Package VonageEscreva o código
Adicione o seguinte ao arquivo ` RevokeMessage.cs`:
var credentials = Credentials.FromAppIdAndPrivateKeyPath(VONAGE_APPLICATION_ID, VONAGE_PRIVATE_KEY_PATH);
var vonageClient = new VonageClient(credentials);
await vonageClient.MessagesClient.UpdateAsync(RcsUpdateMessageRequest.Build(MESSAGES_MESSAGE_ID));Pré-requisitos
Se você não tiver um aplicativo, acesse criar um. Certifique-se também de acessar configure seus webhooks.
composer require vonage/clientCrie um arquivo chamado ` revoke-message.php ` e insira o seguinte código:
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client($keypair);Escreva o código
Adicione o seguinte ao arquivo ` revoke-message.php`:
$messageUuid = '1a5737ad-efd8-4efb-8edd-70d5b8b4ada7';
$client->messages()->updateRcsStatus($messageUuid, \Vonage\Messages\Client::RCS_STATUS_REVOKED);Execute seu código
Salve este arquivo no seu computador e execute-o:
Pré-requisitos
Se você não tiver um aplicativo, acesse criar um. Certifique-se também de acessar configure seus webhooks.
pip install vonage python-dotenvEscreva o código
Adicione o seguinte ao arquivo ` revoke-message.py`:
from vonage import Auth, Vonage
client = Vonage(
auth=Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_PRIVATE_KEY,
)
)
response = client.messages.revoke_rcs_message(MESSAGES_MESSAGE_ID)
print(response)Execute seu código
Salve este arquivo no seu computador e execute-o:
Pré-requisitos
Se você não tiver um aplicativo, acesse criar um. Certifique-se também de acessar configure seus webhooks.
gem install vonageCrie um arquivo chamado ` revoke-message.rb ` e insira o seguinte código:
client = Vonage::Client.new(
application_id: VONAGE_APPLICATION_ID,
private_key: VONAGE_PRIVATE_KEY,
api_host: GEOSPECIFIC_VONAGE_API_HOST
)Escreva o código
Adicione o seguinte ao arquivo ` revoke-message.rb`:
client.messaging.update(
message_uuid: MESSAGES_MESSAGE_ID,
status: 'revoked'
)Execute seu código
Salve este arquivo no seu computador e execute-o:
Experimente
Ao executar o código, é enviada uma solicitação para revogar a mensagem de saída.