Send inbound messages to a webhook

Overview

Send inbound messages for a phone number to your webhook using /webhook

URI

POST to https://api.intelepeer.com/sms/v1/{tn}/webhook

{tn} is the phone number to be configured in E.164 format.

 

For example, you would configure the webhook for +17208675309 by POST-ing to the URL

https://api.intelepeer.com/sms/v1/+17208675309/webhook

 

Parameters

This API method requires an Authorization token. Learn more about the Authorization token in Atmosphere® API Authentication.

ParameterData TypeRequiredDescription
webhookstringrequiredThe URL to where inbound messages will be posted by IntelePeer

 

Example
{
    "webhook": "https://www.myserver.com/myapp"
}

 

Response Codes
Response CodeDescription
200Webhook configuration successfully updated.
400One of the following errors occurred:

  • The telephone number is not in the proper E.164 format
  • The telephone number has not been enabled for SMS
400Improperly-formatted URL provided for the webhook.
404The telephone number is not available for use by the customer.

 

Example Code

Java

package main.java.tnActions.inboundWebHook;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.httpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;

public class SetTnWebHook {
	public static void main(String... args) throws Exception {
		final String TN = "INSERT_TELEPHONENUMBER_HERE_IN_E.164_FORMAT";
		final String url = "https://api.intelepeer.com/sms/v1/" + TN + "/webhook";
		final String AUTH_TOKEN = "INSERT_AUTH_TOKEN_HERE";
		
		
		HttpClient httpclient = HttpClientBuilder.create().build();
		HttpPost httpPost = new HttpPost(url);
        
		// add header
		httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
		httpPost.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + AUTH_TOKEN);
                
		// execute GET
		HttpResponse response = httpclient.execute(httpPost);
        
		System.out.println("nSending 'GET' request to URL : " + url);
		System.out.println("Response Code : " + 
                       response.getStatusLine().getStatusCode());

		BufferedReader rd = new BufferedReader(
                       new InputStreamReader(response.getEntity().getContent()));

		StringBuffer result = new StringBuffer();
		String line = "";
		while ((line = rd.readLine()) != null) {
			result.append(line);
		}

		System.out.println(result.toString());
    }
}

 

Node.js

const request = require("request");

///////////////////////////////////////////////////////////////////////////////
/// update these accordingly                                                ///
///////////////////////////////////////////////////////////////////////////////
let authtoken = 'INSERT_AUTH_TOKEN_HERE'
let tn        = 'INSERT_TELEPHONENUMBER_HERE_IN_E.164_FORMAT'
let webhook   = 'INSERT_WEBHOOK_URL_HERE'

///////////////////////////////////////////////////////////////////////////////
/// leave these alone                                                       ///
///////////////////////////////////////////////////////////////////////////////
let payload   = { 'webhook': webhook }
let url       = "https://api.intelepeer.com/sms/v1/" + tn +"/webhook"
let hdrs      = {
    'Content-Type': "application/json",
    'Authorization': "Bearer " + authtoken
    }

///////////////////////////////////////////////////////////////////////////////
/// execute the task and parse results                                      ///
///////////////////////////////////////////////////////////////////////////////
request.post({
    url: url,
    headers: hdrs,
    form: payload
},
(error, response, body) => {        
    let result = JSON.parse(body);
    console.log(result.text);
});

 

PHP

<?php

require '../../vendor/autoload.php';
use GuzzleHttpClient;

###############################################################################
### update these accordingly                                                ###
###############################################################################
$authtoken = 'INSERT_AUTH_TOKEN_HERE';
$tn = 'INSERT_TELEPHONENUMBER_HERE_IN_E.164_FORMAT';
$webhook = 'INSERT_WEBHOOK_URL_HERE';

###############################################################################
### leave these alone                                                       ###
###############################################################################
$url  = "https://api.intelepeer.com/sms/v1/$tn/webhook";
$hdrs = ['Content-Type' => "application/json",
         'Authorization' => 'Bearer '.$authtoken
];
$payload = ['webhook' => $webhook];

###############################################################################
### execute the task and parse results                                      ###
###############################################################################

try{
  $client = new Client();
  $response = $client->post($url, [
    'headers' => $hdrs,
    'json' => $payload
    ]);
}
catch (RequestException $e){
  echo "Request Failed:". $e->getMessage();
}

echo $response->getBody();
?>

 

Python

import requests

###############################################################################
### update these accordingly                                                ###
###############################################################################
authtoken = 'INSERT_AUTH_TOKEN_HERE'
tn        = 'INSERT_TELEPHONENUMBER_HERE_IN_E.164_FORMAT'
webhook   = 'INSERT_WEBHOOK_URL_HERE'

###############################################################################
### leave these alone                                                       ###
###############################################################################
payload   = { 'webhook': webhook }
url       = "https://api.intelepeer.com/sms/v1/{}/webhook".format(tn)
hdrs      = {
    'Content-Type': "application/json",
    'Authorization': 'Bearer {}'.format(authtoken)
    }

###############################################################################
### execute the task and parse results                                      ###
###############################################################################
response = requests.post(url, json=payload, headers=hdrs)
print u'{}: {}'.format('OK' if response else 'ERROR', response.text )