Giter VIP home page Giter VIP logo

trovebuildabot's Introduction

Build-a-Bot Workshop

If you're an organisation that contributes collection records to Trove you can use this code to build your own Twitter bot that responds to user queries and tweets random collection items.

Requirements

Establishing your credentials

To set up your bot you need to create a Twitter account and then generate the necessary authentication keys for both Twitter and Trove.

  1. Get a Trove API key by following these instructions.
  2. Once you have the key insert it in credentials.py.
  3. Decide on a name for your bot and insert it in the appropriate place in trovebot.py (without the @).
  4. Sign up for a Twitter account in the name of your bot.
  5. Go to the Twitter Developer Site and sign in using your bot's details.
  6. Click on 'Create an App' and fill out and submit the form. You don't need a callback url.
  7. On the 'Settings' tab under 'Application type' select the radio button next to 'Read and Write'. Click the 'Update' button.
  8. On the 'Details' tab click the 'Create my access token' button.
  9. If your access token details don't appear, reload the page.
  10. Copy the following values to credentials.py: 'Consumer Key', 'Consumer Secret', 'Access Token', and 'Access Token Secret'.

Identifying your collection

To limit the bot's tweets to your own collection you need to know your organisation's NUC symbol.

  1. Go to the Australian Libraries Gateway.
  2. Click on 'Find a library' and search for your organisation. Note that there may be more than one entry -- perhaps one for your library and one for your collection or repository.
  3. Click on the 'More details' button.
  4. Look for the NUC symbol and copy it. It may be just a four letter code, or a four letter code followed by a colon and further letters eg: 'AMOA' or 'AMOA:C'.
  5. Copy the NUC symbol to the appropriate place in trovebot.py.

Other configuration options

By default the bot will treat every tweet sent to it as a query to be used to search the collection. If you want to use your bot account to have human-mediated conversations, you might want to change this. Set

AUTO_REPLY = False

and tweets will only be treated as queries if they include the hashtag '#q'. You might also want to change the default GREETING string to explain this to users.

You also have the option to change where the link in a collection result will go. By default the links go to Trove. If you set

DEEP_LINK = True

the bot will use the deep link into the original collection database, assuming that one is available.

Deploying your bot

You don't need anything fancy to host your bot, just a machine permanently connected to the net. If you're deploying to a server, you might need to set the path values in file_locations_prod.py. If that's the case, don't upload file_locations_dev.py.

Activating your bot

In a terminal go to the directory containing your bot's files.

To make it reply to queries enter:

python trovebot.py reply

To make it tweet a random collection item enter:

python trovebot.py random

You probably want to set these up to run at regular intervals using something like cron. I tend to run the 'reply' script every five minutes, and the 'random' script every few hours.

Basic bot behaviours

  • Include the word 'hello' in a message to your bot to receive a greeting and a random collection item.
  • Any other message will be treated as a query and will be sent off to the Trove API to look for matching results.
  • To receive any old random collection item, just tweet your bot the hashtag '#luckydip' and nothing else.

Modifying your bot query

By default, your bot tweets the first (ie most relevant) matching result back to you. To change this you can:

  • Include the hashtag '#luckydip' to receive a random item from the matching results.

By default, the search terms you supply are sent directly to the Trove API without any modification. To change this you can:

  • Include the hashtag '#any' to search for items that match any of your search terms. This is the same as adding an 'OR' between your terms.

Credits

Built by @wragge using the Trove API and the Twitter API.

Released under CC0 licence.

trovebuildabot's People

Contributors

mattrob avatar wragge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.