2017-08-24 14:31:58 +02:00
|
|
|
|
Fetch tweets from Twitter in Zulip! This is great for seeing and
|
2017-06-05 22:29:31 +02:00
|
|
|
|
discussing who is talking about you, friends, competitors, or
|
|
|
|
|
important topics in real time.
|
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. {!create-stream.md!}
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Next, on your {{ settings_html|safe }},
|
|
|
|
|
[create a bot](/help/add-a-bot-or-integration) for
|
|
|
|
|
{{ integration_display_name }}. Make sure that you select
|
|
|
|
|
**Incoming webhook** as the **Bot type**:
|
2017-08-24 14:31:58 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
![Bot types](/static/images/integrations/bot_types.png)
|
2017-08-24 14:31:58 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
The API keys for "Incoming webhook" bots are limited to only
|
|
|
|
|
sending messages via webhooks. Thus, this bot type lessens
|
|
|
|
|
the security risks associated with exposing the bot's API
|
|
|
|
|
key to third-party services.
|
2017-08-24 14:31:58 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Download your new bot's `zuliprc` configuration file.
|
2017-08-24 14:31:58 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. {!download-python-bindings.md!}
|
2017-06-22 02:50:45 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. The Twitter bot should be set up on a trusted machine, because your API
|
|
|
|
|
key is visible to local users through the command line or config
|
|
|
|
|
file.
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Next, install **version 1.0 or later** of the `python-twitter`
|
|
|
|
|
library. If your operating system distribution doesn’t package a new
|
|
|
|
|
enough version, you can install the library from source from
|
|
|
|
|
[the GitHub repository](https://github.com/bear/python-twitter).
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Next, set up Twitter authentication. This bot uses OAuth to
|
|
|
|
|
authenticate with Twitter, and in order to obtain a consumer key &
|
|
|
|
|
secret, you must register a new application under your Twitter
|
|
|
|
|
account:
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Log in to <https://apps.twitter.com/>.
|
2017-06-22 02:50:45 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Click on `Create New App` and fill out the form.
|
2017-06-22 02:50:45 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Click on the application you created and click **create my access
|
|
|
|
|
token**. Fill in the requested values.
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
|
|
|
|
1. Create a `~/.zulip_twitterrc` with the following contents:
|
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
```
|
|
|
|
|
[twitter]
|
|
|
|
|
consumer_key =
|
|
|
|
|
consumer_secret =
|
|
|
|
|
access_token_key =
|
|
|
|
|
access_token_secret =
|
|
|
|
|
```
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Place your bot's `zuliprc` in a directory of your choice (for the next step,
|
|
|
|
|
`~/zuliprc` is used).
|
2017-08-24 14:31:58 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Test the script by running it manually:
|
2017-08-24 14:31:58 +02:00
|
|
|
|
|
|
|
|
|
/usr/local/share/zulip/integrations/twitter/twitter-bot --search="@nprnews,quantum
|
2017-11-06 13:23:14 +01:00
|
|
|
|
physics" --config-file=~/zuliprc
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2017-08-24 14:31:58 +02:00
|
|
|
|
/usr/local/share/zulip/integrations/twitter/twitter-bot --twitter-name="<@your-
|
2017-11-06 13:23:14 +01:00
|
|
|
|
twitter-handle>" --config-file=~/zuliprc
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2017-08-24 14:31:58 +02:00
|
|
|
|
Note: `twitter-bot` may install to a different location on
|
2017-06-05 22:29:31 +02:00
|
|
|
|
your operating system distribution.
|
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. Configure a crontab entry for this script. A sample crontab entry
|
2017-06-22 02:50:45 +02:00
|
|
|
|
that will process tweets every minute is:
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
```
|
|
|
|
|
* * * * * /usr/local/share/zulip/integrations/twitter/twitter-bot --search="@nprnews,
|
|
|
|
|
quantum physics" --config-file=~/zuliprc
|
|
|
|
|
```
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2021-03-16 00:05:05 +01:00
|
|
|
|
1. When someone tweets a message containing one of your search terms,
|
|
|
|
|
get a Zulip on your specified stream, with the search term as
|
|
|
|
|
the topic.
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2017-06-22 02:50:45 +02:00
|
|
|
|
{!congrats.md!}
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2020-08-05 11:50:17 +02:00
|
|
|
|
![Twitter bot message](/static/images/integrations/twitter/001.png)
|
2017-06-05 22:29:31 +02:00
|
|
|
|
|
2017-06-22 02:50:45 +02:00
|
|
|
|
Note that the Twitter search bot integration **just sends links to
|
2017-06-05 22:29:31 +02:00
|
|
|
|
tweets**; the pretty inline previews of tweets are generated by the
|
|
|
|
|
Twitter card rendering integration configured in
|
|
|
|
|
`/etc/zulip/settings.py` on the Zulip server.
|