top of page
Search
  • addressable

Sending Handwritten Letters with Addressable and RapidAPI


Introduction

Programmatic interfaces to communication channels such as SMS, phone calls, faxes, etc., have brought wide ranging capabilities to internet platforms to reach customers, partners, and prospects in new ways. Because many of these services leverage APIs for interfacing, novel dynamic content can be sent to end users - just as with email. However, this has also lead to end users being inundated with an unwanted barrage of messages, essentially extending SPAM emails to our phone calls and text messages. Addressable has come to market with a novel robotic technology capable of sending meaningful and individually unique handwritten messages via mail. These letters can be triggered via an API request to Addressable's unqiue robotic infrastructure, meaning that cloud internet platforms can leverage a new communication medium that grabs the hearts and minds of users.


RapidAPI Launch

With the launch of Addressable's integration with RapidAPI, leveraging meaningful handwritten letters as a programmatic communication medium with your end users has never been easier. Addressable offers direct pricing plans through RapidAPI, and can leverage your existing RapidAPI key. In this post, we will review a step-wise tutorial that demonstrates sending an event-driven life-cycle handwritten notes to be sent to a customer.


Event Driven Communication

As your end users interact with your software, there may be points in time when you may want to reach out to them and extend a thank you message, or a discount to enocurage them to renew your service showing your gratitude for their business..


Node.js Example Integration

RapidAPI utilizes the `unirest` Node.js module to make asynchronous HTTP requests from your back-end web service to the RapidAPI service. The module can be installed by adding it to yarn or npm:


npm

$ npm install --save unirest

yarn

$ yarn add unirest

Now that the unirest module has been added as a dependency to your application, begin by importing the unirest module into your Node.js backend, in the same source file where you will instantiate the event that triggers sending a message to your user. We will also be using the popular Node.js datetime module, moment.


var unirest = require("unirest");
var moment = require("moment");

req.headers({
    "x-rapidapi-host": "addressable.p.rapidapi.com",
    "x-rapidapi-key": "43acaade8fmsh0d6ad64edee8152p115f30jsne347496f06a8",
    "content-type": "application/json",
    "accept": "application/json",
    "useQueryString": true
});

Now, let us define a function that is called when a user is up for renewal. This function could be invoked via a batch cronjob, for example, when a user is 20 days away from renewal. A common strategy for accomplishing such a scheduled job is with the Node module, agenda. Agenda uses MongoDB as a data-store to manage state of jobs and the details of all the jobs. Because of this, metadata can be stored with the job and later recalled when the job is processed.


So, let us define an async job called, "20 days from renewal". To learn more about how to setup Agenda, follow the (agenda documentation)[https://github.com/agenda/agenda] on Github. As a quick overview of how Agenda could be setup, in this example, we have defined a daily running job that queries all user accounts, and checks if renewal is due in 20 days.


If the User's subscription is due in 20 days, then an API request is made to RapidAPI, along with the necessary information to forward to Addressable.


agenda.define('20 days from renewal', {priority: 'high', concurrency: 1}, function(job, done) {
	
	// using momentjs we can check if there are less than 20 days before the end of the User's subscription
	var now = moment();

	var subscription_end = moment(job.attrs.data.user.subscription_end_date);

	var days = now.diff(subscription_end, 'days');

	// If the subscription is due for renewal in 20 days, then send a handwritten note to the user!
	if (days == 20) {
		// Derfines the RapidAPI Addressable Cusxtom Notes endpoint
		var req = unirest("POST", "https://addressable.p.rapidapi.com/custom_notes.json");

		// Sets the necessary Authentication headers
		// Include your RapidAPI key here
		req.headers({
			"x-rapidapi-host": "addressable.p.rapidapi.com",
			"x-rapidapi-key": "----your-rapidapi-key-here----",
			"content-type": "application/json",
			"accept": "application/json",
			"useQueryString": true
		});

		// Sets the Request body type to JSON
		req.type("json");

		// Specifies all values in the JSON body necessary to send the handwritten note!
		// There are some key values set within this JSON body to be sent to Addressable:

		// 1. body: This is a long string that is the message to be handwritten on the card. Note that Merge Variables can
		// be used to insert values, with the format {{key_name}}. In this example, we use the {{first_name}} tag to
		// insert the First name of the end user. The value for {{first_name}} is
		// defined in the child object called 'merge_variables'.

		// 2. merge_variables: These are values that are inserted into the body text, based on the name of their keys

		
		var custom_note = {
			"custom_note": {
				
				"body": "Hello {{first_name}}, I just wanted to send you a note to say thank you for your business. As you consider renewing, please let me know if I can do anything for you.",

				"merge_variables": { "first_name": job.attrs.data.user.first_name },

				"card_image_url": "https://s3.url/image.jpg",
				
				"card_type": "logo",
				
				"format": "AddressableCard",
				
				"from_address_line_1": "1 polk street",
				"from_address_line_2": "Ste 3",
				"from_business_name": "Addressable",
				"from_city": "San Francisco",
				"from_first_name": "Chris",
				"from_last_name": "Tosswill",
				"from_state": "CA",
				"from_zipcode": "94102",
				
				"handwriting_style": 2,
				
				"to_first_name": job.attrs.data.user.first_name,
				"to_last_name": job.data.attrs.user.last_name,
				"to_address_line_1": job.attrs.data.user.street_line_1,
				"to_address_line_2": job.attrs.data.user.street_line_2,
				"to_city": job.attrs.data.user.city,
				"to_state": job.data.attrs.user.state,
				"to_zipcode": job.data.attrs.user.zipcode
			}
		};

		// Sends the API request with the specifies body contents defined above
		req.send(custom_note);

		req.end(function (res) {
			done();
		});
	}

	// If subscription is not due for renewal in 20 days, finish the job
	else {
		done();
	}
	
});

// Starts the agenda process running
(async function() {
  await agenda.start();

  await agenda.every('1 day', '20 days from renewal');
})();


Handwritten Cards and Letters

With a very simple integration, such as above, all users will now automatically receive a highly personable handwritten card right before their account is due for renewal!


It only takes a moment to gain access to the Addressable RapidAPI integration. The Basic plan requires no monthly commitment, and you are only charged when sending a letter. Larger monthly plans offer discounts. Incorporate a meaningful way to connect with your end users in just minutes by getting started with Addressable, today!

86 views0 comments

Recent Posts

See All
bottom of page