Per iniziare

Tabella dei Contenuti

Questo riferimento ti aiuta a implementare l’API RESTful OneMessage v1. Questa API accetta corpi di richiesta con codifica form e restituisce risposte con codifica JSON. L’API è stateless: tutte le richieste vengono convalidate tramite un token API. Il token API può essere ottenuto manualmente dall’app oneMessage.

Postman

La nostra raccolta Postman ti aiuterà a provare e testare la nostra API. Non dimenticare di inserire i valori corretti nelle variabili per ottenere test di successo.

Clicca sul pulsante “Run in Postman” qui sotto per interagire con la nostra API.

Autenticazione

L’API AllMessage utilizza l’autenticazione Bearer, uno schema di autenticazione HTTP che coinvolge token di sicurezza chiamati token di tipo bearer. Il token di tipo bearer è una stringa crittografata, generata dal nostro server. Puoi visualizzare e gestire i tuoi token dalla pagina delle chiavi API, accessibile dalla barra laterale. I tuoi token garantiscono molti privilegi, quindi assicurati di mantenerli al sicuro! Non condividere i tuoi token in aree accessibili al pubblico come GitHub, codice lato client, ecc.

Tutte le richieste API devono essere effettuate tramite HTTPS. Le chiamate effettuate tramite HTTP semplice non andranno a buon fine. Anche le richieste API senza autenticazione non andranno a buon fine.

Webhooks

I webhook vengono utilizzati per connettere due applicazioni diverse; nel nostro caso, vogliamo connettere la nostra applicazione alla tua. Dovresti utilizzare i webhook per ricevere aggiornamenti in tempo reale sulle tue richieste e sui messaggi ricevuti.

Come aggiungere un nuovo URL Webhook

  1. Vai alle impostazioni
  2. Clicca sulla scheda Profili social
  3. Scegli il profilo social (se non hai profili social, creane uno)
  4. Vai alla scheda Webhook
  5. Clicca su Aggiungi webhook
  6. Inserisci l’URL del webhook
  7. Seleziona gli eventi che desideri ascoltare
  8. Clicca su Crea

Webhook Eventi Messaggi:

 Messaggi:

  • Ricevuti
  • Aggiunti in coda
  • Non riusciti
  • Letti
  • Inviati
  • Consegnati
  • Eliminati

Webhook Eventi Modelli:

Modelli:

  • Creati
  • Approvati
  • Rifiutati

Esempi di risposte webhook:

				
					{
      content: "test",
      sender_name: " ",
      whatsapp_chatid: "ABEGkZmUJpU1Ago-sKAShiRwhMUw",
      message_type: "Recieved",
      onemessage_status: "received",
      customer_phone: "+919994269535",
      message_id: "ABEGkZmUJpU1Ago-sKAShiRwhMUw",
      your_phone_number: "919994269535",
      error_response: null
}
				
			
				
					{
      name: "template with buttons",
      template_uid: "495aede5-48a8-419a-a4cc-0431f0031f97",
      category: "SHIPPING_UPDATE",
      languages: ["en_US"],
      status: "SUBMITTED",
      type: "TEXT",
      header: "",
      body: "test content",
      footer: "Thanks"
}
				
			

Conversazioni

Un modello di messaggio WhatsApp, chiamato anche Messaggio Altamente Strutturato (HSM), è un messaggio predefinito che puoi utilizzare più volte per comunicare con i tuoi clienti ed è necessario per avviare una conversazione aziendale. Un modello di messaggio deve essere approvato prima di poter essere utilizzato per avviare una conversazione. Per avviare una conversazione aziendale, un cliente deve aver acconsentito a ricevere messaggi dalla tua azienda. Queste conversazioni possono essere messaggi di assistenza clienti o promemoria di appuntamenti, aggiornamenti su pagamenti o spedizioni, avvisi e altro ancora. I modelli utilizzano variabili o segnaposto che vengono sostituiti con contenuti dinamici in base ai tuoi dati.

Crea un modello di messaggio WhatsApp

Crea un modello di messaggio WA per avviare una conversazione aziendale

POST
				
					https://{{Workspace_name}}.onemessage.chat/api/v1/{{SocialProfile_id}}/create-wa-template
				
			

Esempi di utilizzo e SDK

				
					curl --location --request POST 'https://{{Workspace_name}}.onemessage.chat/api/v1/{{SocialProfile_id}}/create-wa-template' \
                            --header 'Authorization: Bearer {{Token}}' \
                            --form 'All the body parameters' \
				
			
				
					var myHeaders = new Headers();
                myHeaders.append("Authorization", "Bearer {{Token}}");

                var formdata = new FormData();
                formdata.append("elementName", {{Value}});
                formdata.append("languageCode", {{Value}});
                formdata.append("category", {{Value}});
                formdata.append("header_type", {{Value}});
                formdata.append("vertical", {{Value}});
                formdata.append("body", {{Value}});
                formdata.append("header_text", {{Value}});
                formdata.append("body_footer", {{Value}});
                formdata.append("buttons[]", "{“button_type”:{{Value}},“button_text”:{{Value}},“phone_number”:{{Value}}});
                formdata.append("example", {{Value}});

                var requestOptions = {
                  method: 'POST',
                  headers: myHeaders,
                  body: formdata,
                  redirect: 'follow'
                };

                fetch("https://{{Workspace_name}}.onemessage.chat/api/v1/{{SocialProfile_id}}/create-wa-template", requestOptions)
                  .then(response => response.text())
                  .then(result => console.log(result))
                  .catch(error => console.log('error', error));
				
			
				
					{
      name: "template with buttons",
      template_uid: "495aede5-48a8-419a-a4cc-0431f0031f97",
      category: "SHIPPING_UPDATE",
      languages: ["en_US"],
      status: "SUBMITTED",
      type: "TEXT",
      header: "",
      body: "test content",
      footer: "Thanks"
}
				
			

Parametri

NomeDescrizione
Workspace_name*
String Required
Il nome del tuo workspace
SocialProfile_id*
Long Required
L'id del profilo Social a cui vuoi associare il nuovo template

Body

				
					{
elementName:	
string
example: Test Template
languageCode:	
string
example: en_US
category:	
string
example: System Update
header_type:	
string
example: text
vertical:	
string
example: System Update
body:	
string
example: your ticket has been confirmed
header_text:	
string
example: Template header_text
body_footer:	
string
example: Template body_footer
buttons[]:	
 {
button_type:	
string
example: phone_number
button_text:	
string
example: call us
phone_number:	
varchar
example: +919872329959
}
example:	
string
example: your ticket has been confirmed
}
				
			

Risposte

Status: 200 – Template created Successfully


Status: 400 – Bad Request (Empty field, Invalid input)


Status: 401 – Unauthorized


Status: 500 – Internal Server Error

Ottieni modelli WhatsApp

Ottieni un elenco di tutti i modelli WhatsApp associati a un profilo social specifico

GET

Esempi di utilizzo e SDK

				
					curl --location --request POST 'https://{{Workspace_name}}.onemessage.chat/api/v1/{{SocialProfile_id}}/create-wa-template' \
                            --header 'Authorization: Bearer {{Token}}' \
                            --form 'All the body parameters' \
				
			
				
					    var myHeaders = new Headers();
                myHeaders.append("Authorization", "Bearer {{Token}}");

                var formdata = new FormData();
                formdata.append("elementName", {{Value}});
                formdata.append("languageCode", {{Value}});
                formdata.append("category", {{Value}});
                formdata.append("header_type", {{Value}});
                formdata.append("vertical", {{Value}});
                formdata.append("body", {{Value}});
                formdata.append("header_text", {{Value}});
                formdata.append("body_footer", {{Value}});
                formdata.append("buttons[]", "{“button_type”:{{Value}},“button_text”:{{Value}},“phone_number”:{{Value}}});
                formdata.append("example", {{Value}});

                var requestOptions = {
                  method: 'POST',
                  headers: myHeaders,
                  body: formdata,
                  redirect: 'follow'
                };

                fetch("https://{{Workspace_name}}.onemessage.chat/api/v1/{{SocialProfile_id}}/create-wa-template", requestOptions)
                  .then(response => response.text())
                  .then(result => console.log(result))
                  .catch(error => console.log('error', error));
                                
				
			
				
					   $curl = curl_init();

                curl_setopt_array($curl, array(
                  CURLOPT_URL => 'https://{{Workspace_name}}.onemessage.chat/api/v1/{{SocialProfile_id}}/create-wa-template',
                  CURLOPT_RETURNTRANSFER => true,
                  CURLOPT_ENCODING => '',
                  CURLOPT_MAXREDIRS => 10,
                  CURLOPT_TIMEOUT => 0,
                  CURLOPT_FOLLOWLOCATION => true,
                  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                  CURLOPT_CUSTOMREQUEST => 'POST',
                  CURLOPT_POSTFIELDS => array('elementName' => {{Value}},'languageCode' => {{Value}},'category' => {{Value}},'header_type' => {{Value}},'vertical' => {{Value}},'body' => {{Value}},'header_text' => {{Value}},'body_footer' => {{Value}},'buttons[]' => '{“button_type”:{{Value}},“button_text”:{{Value}},“phone_number”:{{Value}}}','example' => {{Value}}),
                  CURLOPT_HTTPHEADER => array(
                    'Authorization: Bearer {{Token}}'
                  ),
                ));

                $response = curl_exec($curl);

                curl_close($curl);
                echo $response;
                              
				
			

Parametri

NomeDescrizione
Workspace_name*
String Required
Il nome del tuo workspace
SocialProfile_id*
Long Required
L'id del profilo Social a cui vuoi associare il nuovo template

Risposte

Status: 200 – Successful operation


Status: 400 – Bad Request (Invalid Social Profile id)


Status: 401 – Unauthorized


Status: 500 – Internal Server Error

Manda un messaggio

Manda un messaggio usando un modello approvato

POST
				
					https://{{Workspace_name}}.onemessage.chat/api/v1/send-message
				
			

Esempi di utilizzo e SDK

				
					curl --location --request POST 'https://{{Workspace_name}}.onemessage.chat/api/v1/send-message' \
                            --header 'Authorization: Bearer {{Token}}' \
                            --form 'All the body parameters'
				
			
				
					var myHeaders = new Headers();
                                myHeaders.append("Authorization", "Bearer {{Token}}");

                                var formdata = new FormData();
                                formdata.append("destination", {{Value}});
                                formdata.append("account_number", {{Value}});
                                formdata.append("template", {{Value}});
                                formdata.append("content", {{Value}});

                                var requestOptions = {
                                  method: 'POST',
                                  headers: myHeaders,
                                  body: formdata,
                                  redirect: 'follow'
                                };

                                fetch("https://{{Workspace_name}}.onemessage.chat/api/v1/send-message", requestOptions)
                                  .then(response => response.text())
                                  .then(result => console.log(result))
                                  .catch(error => console.log('error', error));
				
			
				
					$curl = curl_init();

                                curl_setopt_array($curl, array(
                                  CURLOPT_URL => 'https://{{Workspace_name}}.onemessage.chat/api/v1/send-message',
                                  CURLOPT_RETURNTRANSFER => true,
                                  CURLOPT_ENCODING => '',
                                  CURLOPT_MAXREDIRS => 10,
                                  CURLOPT_TIMEOUT => 0,
                                  CURLOPT_FOLLOWLOCATION => true,
                                  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                                  CURLOPT_CUSTOMREQUEST => 'POST',
                                  CURLOPT_POSTFIELDS => array('destination' => {{Value}},'account_number' => {{Value}},'template' => {{Value}},'content' => {{Value}}),
                                  CURLOPT_HTTPHEADER => array(
                                    'Authorization: Bearer {{Token}}'
                                  ),
                                ));

                                $response = curl_exec($curl);

                                curl_close($curl);
                                echo $response;
				
			

Parametri

NomeDescrizione
Workspace_name*
String Required
Il nome del tuo workspace

Body

				
					{
account_number:	
Long
example: 5
content:	
string
example: Hello
destination:	
Long
example: 9199x426x5x5
template:	
Long
example: template_id
}
				
			

Risposte

Status: 200 – Successful operation


Status: 400 – Bad Request (Empty field, Invalid input)


Status: 401 – Unauthorized


Status: 500 – Internal Server Error