{"id":2555,"date":"2017-10-17T16:09:27","date_gmt":"2017-10-17T14:09:27","guid":{"rendered":"http:\/\/mariusbancila.ro\/blog\/?p=2555"},"modified":"2017-10-17T16:09:27","modified_gmt":"2017-10-17T14:09:27","slug":"how-to-write-a-twitter-bot-in-no-time","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/","title":{"rendered":"How to write a Twitter bot in no time"},"content":{"rendered":"<p>I had recently played with the idea of creating a twitter bot, not for any specific reason but to see how hard or easy that would be. And to do something that would put a bit of fun into the experience I decided to make a bot that would create nice tweets with emoji of bugs. Here is an example:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tweet.png\" alt=\"\" width=\"633\" height=\"453\" class=\"alignnone size-full wp-image-2556\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tweet.png 633w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tweet-300x215.png 300w\" sizes=\"auto, (max-width: 633px) 100vw, 633px\" \/><br \/>\nIt turned out that creating such a bot is a no time consumer when done in JavaScript with Node. The result of my experiment is available here: <a href=\"https:\/\/twitter.com\/emojibugs\">https:\/\/twitter.com\/emojibugs<\/a>. <\/p>\n<p>This article explains the necessary steps to build a simple Twitter bot that posts messages periodically, at some pre-defined interval.<\/p>\n<h3>Twitter account and app<\/h3>\n<p>The first thing to start with is a Twitter account. This could be either an existing account or a new one. <\/p>\n<p>After setting up the account the bot should be tweeting on behalf of you need to go and create an application. That can be done from <a href=\"https:\/\/apps.twitter.com\/\">https:\/\/apps.twitter.com\/<\/a>. You need to create a new app, provide a name, description, website and other optional ones.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp1.png\" alt=\"\" width=\"839\" height=\"597\" class=\"alignnone size-full wp-image-2558\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp1.png 839w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp1-300x213.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp1-768x546.png 768w\" sizes=\"auto, (max-width: 839px) 100vw, 839px\" \/><\/p>\n<p>After the app is created you need to go to Keys and Access Tokens and generate them for the application. These will be used later on to sign it to Twitter from the bot, and specifically:<\/p>\n<ul>\n<li>Consumer key (API key)<\/li>\n<li>Consumer secret (API secret)<\/li>\n<li>Access token<\/li>\n<li>Access token secret<\/li>\n<\/ul>\n<p><strong>NOTE<\/strong>: should these keys and secrets be compromised new ones can be generated (which invalidates the previous ones).<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp2.png\" alt=\"\" width=\"964\" height=\"582\" class=\"alignnone size-full wp-image-2559\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp2.png 964w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp2-300x181.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp2-768x464.png 768w\" sizes=\"auto, (max-width: 964px) 100vw, 964px\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp3.png\" alt=\"\" width=\"959\" height=\"455\" class=\"alignnone size-full wp-image-2560\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp3.png 959w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp3-300x142.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tapp3-768x364.png 768w\" sizes=\"auto, (max-width: 959px) 100vw, 959px\" \/><\/p>\n<h3>Creating a bot in JavaScript<\/h3>\n<p>A very simple solution for a simple bot like this is creating a Node package in JavaScript. Node.js is a JavaScript runtime built on Chrome&#8217;s V8 JavaScript engine that enables running JavaScript code outside the browser. Node comes with npm, which is a package manager for JavaScript.<\/p>\n<p>Download and install Node.js: <a href=\"https:\/\/nodejs.org\/en\/\">https:\/\/nodejs.org\/en\/<\/a><br \/>\nLearn more about npm: <a href=\"https:\/\/www.npmjs.com\/\">https:\/\/www.npmjs.com\/<\/a><\/p>\n<p>There is a Node package for the Twitter client API. It&#8217;s called <a href=\"https:\/\/www.npmjs.com\/package\/twit\">twit<\/a> and is very easy to use. The following is the only JavaSCript code you need to write to post a new tweet with the text &#8220;hello world!&#8221; on the registered account.<\/p>\n<pre class=\"lang:js decode:true \" >\r\nvar Twit = require('twit');\r\n \r\nvar T = new Twit({\r\n  consumer_key:         '...',\r\n  consumer_secret:      '...',\r\n  access_token:         '...',\r\n  access_token_secret:  '...',\r\n});\r\n \r\nT.post(\r\n  'statuses\/update', \r\n  { status: 'hello world!' }, \r\n  function(err, data, response) {\r\n    console.log(data)\r\n  });<\/pre>\n<p>What you need to do here is fill in the API key and secret and the access token and secret with the ones generated for your app.<\/p>\n<h3>Creating a Node package<\/h3>\n<p>To create a new package go to an empty folder where you want to locate the package and run the <tt>npm init<\/tt> command in a console. This will prompt you to provide some information (some of which are already filled in for you).<\/p>\n<pre class=\"lang:default decode:true \" >C:\\demo\\emojibugs&gt;npm init\r\nThis utility will walk you through creating a package.json file.\r\nIt only covers the most common items, and tries to guess sensible defaults.\r\n\r\nSee `npm help json` for definitive documentation on these fields\r\nand exactly what they do.\r\n\r\nUse `npm install &lt;pkg&gt; --save` afterwards to install a package and\r\nsave it as a dependency in the package.json file.\r\n\r\nPress ^C at any time to quit.\r\nname: (emojibugs)\r\nversion: (1.0.0)\r\ndescription: A bot that posts messages to Twitter.\r\nentry point: (index.js) bot.js\r\ntest command:\r\ngit repository:\r\nkeywords: twitter bot app\r\nauthor: Marius Bancila\r\nlicense: (ISC) GPL-3.0\r\nAbout to write to C:\\Work\\demo\\emojibugs\\package.json:\r\n\r\n{\r\n  \"name\": \"emojibugs\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"A bot that posts messages to Twitter.\",\r\n  \"main\": \"bot.js\",\r\n  \"scripts\": {\r\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\r\n  },\r\n  \"keywords\": [\r\n    \"twitter\",\r\n    \"bot\",\r\n    \"app\"\r\n  ],\r\n  \"author\": \"Marius Bancila\",\r\n  \"license\": \"GPL-3.0\"\r\n}\r\n\r\n\r\nIs this ok? (yes) yes\r\n<\/pre>\n<p>There result is a file called <tt>package.json<\/tt> that describes the Node package and its dependencies.<\/p>\n<pre class=\"lang:js decode:true \" >{\r\n  \"name\": \"emojibugs\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"A bot that posts messages to Twitter.\",\r\n  \"main\": \"bot.js\",\r\n  \"scripts\": {\r\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\r\n  },\r\n  \"keywords\": [\r\n    \"twitter\",\r\n    \"bot\",\r\n    \"app\"\r\n  ],\r\n  \"author\": \"Marius Bancila\",\r\n  \"license\": \"GPL-3.0\"\r\n}\r\n<\/pre>\n<p>To install the <tt>twit<\/tt> package for the Twitter client api run the following command in a console in the folder where the package is located:<\/p>\n<pre class=\"lang:default decode:true \" >npm install twit --save<\/pre>\n<p>The twit module and all its dependencies will be downloaded in this folder and the <tt>package.json<\/tt> file updated with the dependency:<\/p>\n<pre class=\"lang:js decode:true \" >{\r\n  \"name\": \"emojibugs\",\r\n  \"version\": \"1.0.0\",\r\n  \"description\": \"A bot that posts messages to Twitter.\",\r\n  \"main\": \"bot.js\",\r\n  \"scripts\": {\r\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\r\n  },\r\n  \"keywords\": [\r\n    \"twitter\",\r\n    \"bot\",\r\n    \"app\"\r\n  ],\r\n  \"author\": \"Marius Bancila\",\r\n  \"license\": \"GPL-3.0\",\r\n  \"dependencies\": {\r\n    \"twit\": \"^2.2.9\"\r\n  }\r\n}<\/pre>\n<h3>Writing the bot<\/h3>\n<p>When we created the Node package we specified that the entry point should be a file called <tt>bot.js<\/tt>. We need to create this and fill it with the following code:<\/p>\n<pre class=\"lang:js decode:true \" >\r\nvar Twit = require('twit');\r\n \r\nvar T = new Twit({\r\n  consumer_key:         '...',\r\n  consumer_secret:      '...',\r\n  access_token:         '...',\r\n  access_token_secret:  '...',\r\n});\r\n\r\n\/\/ tweet at startup\r\ntweetIt();\r\n\r\n\/\/ tweet every 6 hours\r\nsetInterval(tweetIt, 1000 * 60 * 60 * 6);\r\n\r\nfunction generateText() { }\r\n\r\nfunction tweetIt() \r\n{\r\n   T.post(\r\n      'statuses\/update',\r\n      {\r\n         status: generateText()\r\n      },\r\n      function (err, data, response) {\r\n         if (err) {\r\n            console.log(\"Something went wrong\");\r\n         } else {\r\n            console.log(\"Tweet posted\");\r\n         }\r\n      }\r\n   );\r\n}<\/pre>\n<p>The function <tt>generateText<\/tt> creates the text to be posted in a tweet. It can do anything and for the sake of this post its content is irrelevant. Function <tt>tweetIt<\/tt> does a status update with a text generated by <tt>generateText<\/tt>. This function is executed both when the package is run the first time as well as every six hours (a timer is created with <tt>setInterval<\/tt>).<\/p>\n<h3>Running the bot locally<\/h3>\n<p>You can run the script locally in two ways:<\/p>\n<ul>\n<li>By running the following command:\n<pre class=\"lang:default decode:true \" >node bot.js<\/pre>\n<\/li>\n<li>By adding a script to <tt>package.json<\/tt> and execuring that script.\n<pre class=\"lang:js decode:true \" >\"scripts\": {\r\n    \"start\": \"node bot.js\",\r\n    \"test\": \"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"\r\n  },<\/pre>\n<p>And then executing the following command:<\/p>\n<pre class=\"lang:default decode:true \" >npm start<\/pre>\n<\/li>\n<\/ul>\n<h3>It&#8217;s done<\/h3>\n<p>That is all that is necessary for a Twitter bot to run and post to a Twitter account. Of course, there are things that have been let aside, such as how to generate the content of the message, how to host the bot on a cloud platform, or how to write a bot that does more that posting text, such as posting images, replying, etc. But some of that in the next article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had recently played with the idea of creating a twitter bot, not for any specific reason but to see how hard or easy that would be. And to do something that would put a bit of fun into the experience I decided to make a bot that would create nice tweets with emoji of &#8230; <a title=\"How to write a Twitter bot in no time\" class=\"read-more\" href=\"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/\" aria-label=\"Read more about How to write a Twitter bot in no time\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[519,19],"tags":[522,521,293,523,442,524,520],"class_list":["post-2555","post","type-post","status-publish","format-standard","hentry","category-javascript","category-web","tag-app","tag-bot","tag-javascript","tag-node","tag-npm","tag-package","tag-twitter"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"description\" content=\"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"twitter,bot,app,javascript,node,npm,package\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"How to write a Twitter bot in no time\" \/>\n\t\t<meta property=\"og:description\" content=\"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2017-10-17T14:09:27+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2017-10-17T14:09:27+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"How to write a Twitter bot in no time\" \/>\n\t\t<meta name=\"twitter:description\" content=\"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#article\",\"name\":\"How to write a Twitter bot in no time\",\"headline\":\"How to write a Twitter bot in no time\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/wp-content\\\/uploads\\\/2017\\\/10\\\/tweet.png\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#articleImage\",\"width\":633,\"height\":453},\"datePublished\":\"2017-10-17T16:09:27+02:00\",\"dateModified\":\"2017-10-17T16:09:27+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":1,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#webpage\"},\"articleSection\":\"JavaScript, Web, app, bot, javascript, node, npm, package, twitter\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/web\\\/#listItem\",\"name\":\"Web\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/web\\\/#listItem\",\"position\":3,\"name\":\"Web\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/web\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/web\\\/javascript\\\/#listItem\",\"name\":\"JavaScript\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/web\\\/javascript\\\/#listItem\",\"position\":4,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/web\\\/javascript\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#listItem\",\"name\":\"How to write a Twitter bot in no time\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/web\\\/#listItem\",\"name\":\"Web\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#listItem\",\"position\":5,\"name\":\"How to write a Twitter bot in no time\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/web\\\/javascript\\\/#listItem\",\"name\":\"JavaScript\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/\",\"name\":\"How to write a Twitter bot in no time\",\"description\":\"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2017\\\/10\\\/17\\\/how-to-write-a-twitter-bot-in-no-time\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2017-10-17T16:09:27+02:00\",\"dateModified\":\"2017-10-17T16:09:27+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How to write a Twitter bot in no time","description":"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js.","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/","robots":"max-image-preview:large","keywords":"twitter,bot,app,javascript,node,npm,package","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#article","name":"How to write a Twitter bot in no time","headline":"How to write a Twitter bot in no time","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2017\/10\/tweet.png","@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#articleImage","width":633,"height":453},"datePublished":"2017-10-17T16:09:27+02:00","dateModified":"2017-10-17T16:09:27+02:00","inLanguage":"en-US","commentCount":1,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#webpage"},"articleSection":"JavaScript, Web, app, bot, javascript, node, npm, package, twitter"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/#listItem","name":"Web"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/#listItem","position":3,"name":"Web","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/javascript\/#listItem","name":"JavaScript"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/javascript\/#listItem","position":4,"name":"JavaScript","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/javascript\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#listItem","name":"How to write a Twitter bot in no time"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/#listItem","name":"Web"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#listItem","position":5,"name":"How to write a Twitter bot in no time","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/javascript\/#listItem","name":"JavaScript"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/","name":"How to write a Twitter bot in no time","description":"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2017-10-17T16:09:27+02:00","dateModified":"2017-10-17T16:09:27+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"How to write a Twitter bot in no time","og:description":"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js.","og:url":"https:\/\/mariusbancila.ro\/blog\/2017\/10\/17\/how-to-write-a-twitter-bot-in-no-time\/","article:published_time":"2017-10-17T14:09:27+00:00","article:modified_time":"2017-10-17T14:09:27+00:00","twitter:card":"summary","twitter:title":"How to write a Twitter bot in no time","twitter:description":"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js."},"aioseo_meta_data":{"post_id":"2555","title":"How to write a Twitter bot in no time","description":"This article shows how to create an application that post messages to a Twitter account in JavaScript using Node.js.","keywords":[{"label":"twitter","value":"twitter"},{"label":"bot","value":"bot"},{"label":"app","value":"app"},{"label":"javascript","value":"javascript"},{"label":"node","value":"node"},{"label":"npm","value":"npm"},{"label":"package","value":"package"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-03-18 21:06:01","updated":"2025-12-12 07:46:59","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":1,"uagb_excerpt":"I had recently played with the idea of creating a twitter bot, not for any specific reason but to see how hard or easy that would be. And to do something that would put a bit of fun into the experience I decided to make a bot that would create nice tweets with emoji of&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/javascript\/\" class=\"advgb-post-tax-term\">JavaScript<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">Web<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">JavaScript<\/span>","<span class=\"advgb-post-tax-term\">Web<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">app<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">bot<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">javascript<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">node<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">npm<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">package<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/web\/\" class=\"advgb-post-tax-term\">twitter<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">app<\/span>","<span class=\"advgb-post-tax-term\">bot<\/span>","<span class=\"advgb-post-tax-term\">javascript<\/span>","<span class=\"advgb-post-tax-term\">node<\/span>","<span class=\"advgb-post-tax-term\">npm<\/span>","<span class=\"advgb-post-tax-term\">package<\/span>","<span class=\"advgb-post-tax-term\">twitter<\/span>"]}},"comment_count":"1","relative_dates":{"created":"Posted 9 years ago","modified":"Updated 9 years ago"},"absolute_dates":{"created":"Posted on October 17, 2017","modified":"Updated on October 17, 2017"},"absolute_dates_time":{"created":"Posted on October 17, 2017 4:09 pm","modified":"Updated on October 17, 2017 4:09 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-Fd","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=2555"}],"version-history":[{"count":10,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2555\/revisions"}],"predecessor-version":[{"id":2569,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/2555\/revisions\/2569"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=2555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=2555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=2555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}