Real-time Chat Blog

Build a Twitter Chatbot with PubNub Functions

2 min read Adam Bavosa on Mar 16, 2018
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

How to create a Twitter chatbot with PubNub Functions that automatically responds to customers, activity, and more.

So you want to create a Twitter bot to interact with your customers automatically. This can be configured and deployed today using PubNub Functions with our Twitter BLOCK.


A Practical Use Case

The Open Growth SDK uses Machine Learning to intelligently get in touch with your customers in real time. No more email blasts, no more watching leads, no more delay in communication. The instant a customer signs up for your service, they are classified to determine what their needs will be. The Delight Engine automatically reaches out with specific resources for the customer’s likely use case.

Open Growth sends that introduction via email, text message, Twitter, and even cake 🍰 ! This guide shows how to configure your company’s Twitter account to post automated @tweets to your customers (following the docs):

  • Sign up for a Twitter account, or log into an existing one.
  • Sign in, go to the Twitter Application Management Dashboard, click Create New App and fill in all the fields except for Callback URL.
  • Click Create Your Twitter Application.
  • Go to the Permissions tab an make sure the app’s permissions are set to Read and Write.
  • Next, you need grant access and get an OAuth token. You can get the consumer keys and generate the tokens on the Keys and Access Tokens page by hitting the Create my access token button.
  • Done! You can now use the Twitter BLOCK to Tweet by publishing a PubNub message or REST API call.

Test and Debug

Besides hitting the Create my access token button, you can use PIN-based authorization. You can authorize and also debug using Twurl, a command line tool like Curl, but tailored for Twitter. If you have Ruby installed, you can install Twurl on the command line with:

gem install twurl
  • Have your keys ready from the Twitter application’s Keys and Access Tokens tab on the app page.
twurl authorize --consumer-key "Your app’s consumer key" \
--consumer-secret "Your app’s consumer secret"
  • A URL will be returned on the command line. Visit that URL in a web browser and a pin will be presented. Enter that pin on the command line and your app’s tokens will be ready for use with Functions.
  • Go back to the Keys and Access Tokens page and find your new access tokens.

After you have configured your Twitter app, you can then configure the PubNub Functions event handler. Take the 4 secrets from the Twitter app Keys and Access Tokens tab, and put them into your Functions Vault. This can be accessed from the Functions event handler editor on the left. Click MY SECRETS and enter your keys and values into the vault following the Twitter event handler code. Next press the play button, submit a test payload, and check your Twitter!

You have enabled automated Tweets! Using the PubNub REST API or any SDK, you can programmatically Tweet!

More from PubNub

Top Trends to Engage Your App Users
InsightsSep 27, 20224 min read

Top Trends to Engage Your App Users

Take a look at the top trends that are the most effective in attracting customers and reducing churn, and how you can incorporate...

PubNub Staff

PubNub Staff

Comparing Game Engines: Unity vs Unreal vs the Rest
Real-Time Gaming BlogSep 21, 20225 min read

Comparing Game Engines: Unity vs Unreal vs the Rest

Comparing the major game engines: Unity vs Unreal Engine vs Corona SDK vs GameMaker Studio, including the benefits and cons of...

PubNub Staff

PubNub Staff

Python Socket Programming: Client, Server and Peer Libraries
BuildSep 21, 20226 min read

Python Socket Programming: Client, Server and Peer Libraries

Sockets (aka socket programming) enable programs to send and receive data, bi-directionally, at any given moment. This tutorial...

PubNub Staff

PubNub Staff