zulip_bots: Check Access Token on initialization for Mention bot.
This commit is contained in:
parent
9ac0628452
commit
adbda6d2f2
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
import logging
|
||||||
|
|
||||||
class MentionHandler(object):
|
class MentionHandler(object):
|
||||||
def initialize(self, bot_handler: Any) -> None:
|
def initialize(self, bot_handler: Any) -> None:
|
||||||
|
@ -9,6 +10,23 @@ class MentionHandler(object):
|
||||||
self.access_token = self.config_info['access_token']
|
self.access_token = self.config_info['access_token']
|
||||||
self.account_id = ''
|
self.account_id = ''
|
||||||
|
|
||||||
|
self.check_access_token()
|
||||||
|
|
||||||
|
def check_access_token(self) -> None:
|
||||||
|
test_query_header = {
|
||||||
|
'Authorization': 'Bearer ' + self.access_token,
|
||||||
|
'Accept-Version': '1.15',
|
||||||
|
}
|
||||||
|
test_query_response = requests.get('https://api.mention.net/api/accounts/me', headers=test_query_header)
|
||||||
|
|
||||||
|
try:
|
||||||
|
test_query_data = test_query_response.json()
|
||||||
|
if test_query_data['error'] == 'invalid_grant' and \
|
||||||
|
test_query_data['error_description'] == 'The access token provided is invalid.':
|
||||||
|
logging.error('Access Token Invalid. Please see doc.md to find out how to get it.')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
def usage(self) -> str:
|
def usage(self) -> str:
|
||||||
return '''
|
return '''
|
||||||
This is a Mention API Bot which will find mentions
|
This is a Mention API Bot which will find mentions
|
||||||
|
|
Loading…
Reference in a new issue