interactive bots: Improve wikipedia bot.

This commit is contained in:
sColin16 2017-12-10 16:26:42 +00:00 committed by showell
parent 1221c7107f
commit 6109bd198a
3 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,41 @@
# Wikipedia Bot
The Wikipedia bot is a Zulip bot that will search Wikipedia
for a provided keyword, and fetch a link to the associated
Wikipedia article. The link is returned to the same stream
it was @mentioned in
The Wikipedia bot uses the
[MediaWiki API](https://www.mediawiki.org/wiki/API:Main_page)
to obtain the search results it returns
Using the Wikipedia bot is as simple as mentioning @\<wikipedia-bot-name\>,
followed by the keyword:
```
@<wikipedia-bot-name> <keyword>
```
## Setup
Beyond the typical obtaining of the zuliprc file, no extra setup is required to use the Wikipedia Bot
## Usage
1. ```@<wikipedia-bot-name> <keyword>``` -
fetches the link to the appropriate Wikipedia article.
* For example, `@<wikipedia-bot-name> Zulip`
will return the link `https://en.wikipedia.org/wiki/Zulip`
<br>
2. If the keyword does not return an article link,
the bot will respond with an error message:
`I am sorry. The search term you provided is not found`
<br>
3. If no keyword is provided, the bot will return the help text:
```Please enter your message after @mention-bot```

View file

@ -0,0 +1,22 @@
{
"request": {
"api_url":"https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=Zulip&format=json"
},
"response": {
"data": {
"status_code":404
},
"query": {
"search": [
{
"title":"Number sign"
}
]
}
},
"response-headers":{
"status":404,
"content-type":"text/html"
}
}

View file

@ -55,3 +55,15 @@ class TestWikipediaBot(StubBotTestCase):
bot_request = '' bot_request = ''
bot_response = "Please enter your search term after @mention-bot" bot_response = "Please enter your search term after @mention-bot"
self.verify_reply(bot_request, bot_response) self.verify_reply(bot_request, bot_response)
# Incorrect status code
bot_request = 'Zulip'
bot_response = None
with self.mock_http_conversation('test_status_code'):
self.verify_reply(bot_request, bot_response)
# Request Exception
bot_request = 'Z'
bot_response = None
with self.mock_request_exception():
self.verify_reply(bot_request, bot_response)