{"id":416,"date":"2016-04-04T14:57:14","date_gmt":"2016-04-04T12:57:14","guid":{"rendered":"http:\/\/log.or.cz\/?p=416"},"modified":"2016-04-04T14:57:14","modified_gmt":"2016-04-04T12:57:14","slug":"yodaqa-learned-to-tweet","status":"publish","type":"post","link":"https:\/\/log.or.cz\/?p=416","title":{"rendered":"YodaQA learned to tweet"},"content":{"rendered":"<p align=\"center\"><b>Guest post by Petr Marek <a href=\"http:\/\/petr-marek.com\/blog\/2016\/04\/03\/yodaqa-learned-to-tweet\/\">(source)<\/a><\/b><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\"><a\nhref=\"http:\/\/live.ailao.eu\/\">YodaQA <\/a>learned how to use twitter during easter holidays. You can ask it by sending tweet with question to <a href=\"https:\/\/twitter.com\/askYodaQA\">@askYodaQA<\/a> . YodaQA will answer you shortly. How is it possible? I created app in the Google\u00e2\u20ac\u2122s App Script, which handles receiving question from twitter and answering them.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Why did I create it? YodaQA can reach more users in the new interesting form thanks to it. I believe they will help us to find even more ways how YodaQA can help them. It is pretty symbiosis. YodaQA will help twitter users, and they will help it back. <span style=\"font-weight: 400;\">Let\u00e2\u20ac\u2122s look how it is made.<\/span> <\/span><\/p>\n<p style=\"text-align: justify;\"><a\nhref=\"http:\/\/petr-marek.com\/wp-content\/uploads\/2016\/04\/YodaTwitter.png\"><img\nclass=\" size-full wp-image-1117 aligncenter\"\nsrc=\"http:\/\/petr-marek.com\/wp-content\/uploads\/2016\/04\/YodaTwitter.png\"\nalt=\"YodaQA twitter\" width=\"633\" height=\"368\" \/><\/a><\/p>\n<h3 style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The two important tools<\/span><\/h3>\n<p  style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The most important ingredient was Google\u00e2\u20ac\u2122s App Script. It is basically JavaScript with the connection to Google services. You can make your own App Script apps in Google Drive. The best thing is that you can make triggers run the app every minute for example. And it\u00e2\u20ac\u2122s for free.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The second thing you need is to create twitter app on account, which your bot will use to communicate with its followers. It will grant you access tokens, which you need to connect to twitter API. I used <a href=\"http:\/\/airhadoken.github.io\/2015\/06\/29\/twitter-lib-explained.html\">Twitter Lib for Google Apps Script<\/a> to simplify the communication with API. It allowed me to tweet and get tweets with questions easily. You just need to call the right function with some arguments.<\/span><\/p>\n<h3 style=\"text-align: justify;\"><span style=\"font-weight: 400;\">General idea behind<\/span><\/h3>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">That was the tools that I used. But how did I make it work? I will describe the general idea now. I set App Script project to run my code every minute. The code does basically two things. <\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The first step is to obtain answers from twitter and to ask YodaQA. Bot searches all tweets with <a href=\"https:\/\/twitter.com\/askYodaQA\">@askYodaQA<\/a>. It saves the users that tweeted them and the time when it found the tweets. Then it sends the text of the tweet to YodaQA. YodaQA replies with dialog id and question id, which it saves to the list of questions.<\/span><\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-1114\naligncenter\" src=\"http:\/\/petr-marek.com\/wp-content\/uploads\/2016\/04\/YodaQAConcept.png\"\nalt=\"YodaQA twitter\" width=\"615\" height=\"499\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The second step is to go through list of questions and to ask YodaQA for answers to these questions. Bot sends questions to users as soon as the answers are finished. You can even rely on features of the Hub, such as dialogs and coreference resolution. Two questions are connected to dialog when they are asked within five minutes interval.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">I said that I save some information. Where? I used spreadsheet as memory. I use one sheet as \u00e2\u20ac\u0153user memory\u00e2\u20ac\u009d, the second as \u00e2\u20ac\u0153asked question list\u00e2\u20ac\u009d and the last as memory for the id of the last served tweet. I even log some information into a Google Docs text document. It may sound simple (and it is simple), but it works.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">You can try it right now. Just tweet question with <a href=\"https:\/\/twitter.com\/askYodaQA\">@askYodaQA<\/a> and answer will arrive within few minutes. You can even use hashtags or mention other users. They will also receive the answer.<\/span><span style=\"font-weight: 400;\"> <\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">You can see the whole code on <a\nhref=\"https:\/\/github.com\/brmson\/YodaQA-twitter-bot\">GitHub<\/a>. You can use it and modify it for your own twitter bots too, maybe on your own data?<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Guest post by Petr Marek (source) YodaQA learned how to use twitter during easter holidays. You can ask it by sending tweet with question to @askYodaQA . YodaQA will answer you shortly. How is it possible? I created app in the Google\u00e2\u20ac\u2122s App Script, which handles receiving question from twitter and answering them. Why did [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[150,6],"tags":[149,166,162,165,148],"class_list":["post-416","post","type-post","status-publish","format-standard","hentry","category-ailao","category-software","tag-ailao","tag-guest","tag-students","tag-twitter","tag-yodaqa"],"_links":{"self":[{"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/posts\/416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/log.or.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=416"}],"version-history":[{"count":3,"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/posts\/416\/revisions"}],"predecessor-version":[{"id":419,"href":"https:\/\/log.or.cz\/index.php?rest_route=\/wp\/v2\/posts\/416\/revisions\/419"}],"wp:attachment":[{"href":"https:\/\/log.or.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/log.or.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/log.or.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}