A Twitter bot that tweets a definition of a rare french word and a poll with several words, one being the actual definition's word.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
JeuDuDicoBot.php
LICENSE
README.md
TwitterAPIExchange.php

README.md

Jeu du Dico Bot

A Twitter bot that tweets a definition of a rare french word and a poll with several words, one being the actual definition's word.

The Twitter bot is @JeuDuDicoBot

How it works

The program looks for a word in the rare words database and for three other words with close lexical properties. The tweet is the definition of the first word, the poll choices are made of all the words shuffled. The program then posts the poll and the tweet containing the poll, and stores the tweet's id and the right word for the poll in a database. Next time the program is run, it will begin by tweeting the right answer for the poll in reply to the poll's tweet.

Post a Twitter poll

Posting a Twitter poll is currently not supported in the official Twitter Rest API, so you'll need to hack your way to post one. For that, you must have OAuth Access Tokens for an official Twitter application that supports polls, for instance Twitter for iPhone or Twitter for Android. In this program I used Android, but @fourtonfish has made a good example for iPhone in Python.

  1. Create your Twitter bot's account
  2. Use Twitter's PIN-based authorization with the chosen app's consumer keys and your bot's account to get your official app's OAuth Tokens
  3. Create a Twitter application for your bot and get your app's OAuth Tokens
  4. Create the card_data parameter of your call that looks like this:
  card = {
	'twitter:string:choice1_label': 'choice1',
	'twitter:string:choice2_label': 'choice2',
	'twitter:string:choice3_label': 'choice3',
	'twitter:string:choice4_label': 'choice4',
	'twitter:long:duration_minutes': 1440,
	'twitter:api:api:endpoint': '1',
	'twitter:card': 'poll4choice_text_only', // pollXchoice_text_only if you have X choices (2 <= X <= 4)
    }
  1. Don't forget to stringify (or JSON encode) the card object.
  2. When you make the call to https://caps.twitter.com/v2/cards/create.json, use the user-agent of the official app you chose (in my example: TwitterAndroid/6.45.0 Nexus 4/17 (LGE;mako;google;occam;0))

Databases

It uses two databases:

  • a database of rare french words with their definitions and lexical informations (part of speech, gender and number)
  • a database to store the id of a tweet containing the current poll and the right word for this poll

License

The source code of this bot is available under the terms of the MIT license.