def test_to_json(self): config = Configuration( webhook='https://mybot.com/incoming', features={'manuallySendReadReceipts': True}, static_keyboard=SuggestedResponseKeyboard( responses=[ TextResponse('foo') ] ) ) self.assertEqual(config.to_json(), { 'webhook': 'https://mybot.com/incoming', 'features': { 'manuallySendReadReceipts': True }, 'staticKeyboard': { 'type': 'suggested', 'responses': [ { 'type': 'text', 'body': 'foo' } ] } })
def test_to_json_no_features(self): config = Configuration(webhook='https://mybot.com/incoming') self.assertEqual(config.to_json(), { 'webhook': 'https://mybot.com/incoming', 'features': {} })
def test_to_json_no_features(self): config = Configuration( webhook='https://mybot.com/incoming' ) self.assertEqual(config.to_json(), { 'webhook': 'https://mybot.com/incoming', 'features': {} })
def test_to_json(self): config = Configuration(webhook='https://mybot.com/incoming', features={'manuallySendReadReceipts': True}) self.assertEqual( config.to_json(), { 'webhook': 'https://mybot.com/incoming', 'features': { 'manuallySendReadReceipts': True } })
def test_to_json(self): config = Configuration( webhook='https://mybot.com/incoming', features={'manuallySendReadReceipts': True} ) self.assertEqual(config.to_json(), { 'webhook': 'https://mybot.com/incoming', 'features': { 'manuallySendReadReceipts': True } })
def create_kik_bot(self): self._kik_bot = KikApi( self.configuration.client_configuration.bot_name, self._bot_api_key) self._kik_bot.set_configuration( Configuration( webhook=self.configuration.client_configuration.webhook))
def ApplyConfig(self): global kik self.__SetDefaultFeatures() kik.set_configuration( Configuration(webhook=self.config.webhook, features=self.afeatures, static_keyboard=self.config.staticKeyboard))
def test_from_json(self): config = Configuration.from_json({ 'webhook': 'https://mybot.com/incoming', 'features': { 'manuallySendReadReceipts': True } }) self.assertEqual(config.webhook, 'https://mybot.com/incoming') self.assertEqual(config.features, {'manuallySendReadReceipts': True})
def setup(): """Sets up the bot.""" with open('data.json') as d: config = json.load(d) print(config) app = Flask(__name__) kik = KikApi(config["bot_name"], config["api_key"]) kik.set_configuration(Configuration(webhook=config["hostname"])) blobber = Blobber(analyzer=NaiveBayesAnalyzer()) # , classifier = cl) raven_client = Client(config['sentry_hook']) return app, blobber, config, kik
def test_to_json(self): config = Configuration(webhook='https://mybot.com/incoming', features={'manuallySendReadReceipts': True}, static_keyboard=SuggestedResponseKeyboard( responses=[TextResponse('foo')])) self.assertEqual( config.to_json(), { 'webhook': 'https://mybot.com/incoming', 'features': { 'manuallySendReadReceipts': True }, 'staticKeyboard': { 'type': 'suggested', 'responses': [{ 'type': 'text', 'body': 'foo' }] } })
def create_kik_bot(self): if self._bot_api_key is not None: kik_bot = KikApi(self.configuration.client_configuration.bot_name, self._bot_api_key) kik_bot.set_configuration( Configuration( webhook=self.configuration.client_configuration.webhook)) return kik_bot else: YLogger.error(self, "Kik bot api key missing, unable to create kik bot") return None
def init(): """ Main program """ kik = KikApi(BOT_USERNAME, BOT_API_KEY) # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once # or if the configuration changes. In a production setting, you would only issue this call if you need to change # the configuration, and not every time the bot starts. logging.debug('setting webhook to %s', WEBHOOK) kik.set_configuration(Configuration(webhook=WEBHOOK)) app = KikBot(kik, __name__) if PORT: app.run(port=PORT, host='127.0.0.1', debug=True) # from command line else: return app
def notify_ngrok_worker(): while True: try: sleep(1) ngrok_url = get_ngrok_url() break except KeyboardInterrupt: raise except IndexError: continue logging.debug('ngrok available at {}'.format(ngrok_url)) kik.set_configuration(Configuration(webhook=ngrok_url))
def test_set_configuration(self, post): config = Configuration(webhook='https://example.com/incoming', features={'manuallySendReadReceipts': True}) response = self.api.set_configuration(config) post.assert_called_once_with( 'https://api.kik.com/v1/config', timeout=60, auth=('mybotusername', 'mybotapikey'), headers={'Content-Type': 'application/json'}, data=json.dumps({ 'webhook': 'https://example.com/incoming', 'features': { 'manuallySendReadReceipts': True } })) self.assertEqual(response, {})
def init_app(path): """ Ensure that the configuration file is loaded by the web server before it is given the Flask app. :param path: Location of the json configuration file for the application to be run. :return: The flask app object, to be used as the WSGI application. """ global config, kik, queue, parser with open(path) as config_file: config = json.load(config_file) Database.init_database(config) kik = KikApi(config['bot_username'], config['bot_api_key']) kik.set_configuration(Configuration(webhook=config['webhook'])) queue = MessageQueue(config, kik) parser = MessageParser(config, queue) return app
def __init__(self, username, api_key, webhook, case_sensitive=False, command_list="Commands"): self.functions = {} self.help = {} self.kik = KikApi(username, api_key) self.kik.set_configuration(Configuration(webhook=webhook)) self.case_sensitive = case_sensitive if not isinstance(command_list, str): command_list = None if not case_sensitive: if command_list != None: command_list = command_list.lower() self.command_list_command = command_list self.keyboard_entries = [ self.command_list_command ] if case_sensitive else [self.command_list_command.title()]
def test_from_json(self): config = Configuration.from_json({ 'webhook': 'https://mybot.com/incoming', 'features': { 'manuallySendReadReceipts': True }, 'staticKeyboard': { 'type': 'suggested', 'responses': [{ 'type': 'text', 'body': 'foo' }] } }) self.assertEqual(config.webhook, 'https://mybot.com/incoming') self.assertEqual(config.features, {'manuallySendReadReceipts': True}) self.assertIsInstance(config.static_keyboard, SuggestedResponseKeyboard) self.assertEqual( config.static_keyboard, SuggestedResponseKeyboard(responses=[TextResponse('foo')]))
def test_set_configuration(self, post): config = Configuration(webhook='https://example.com/incoming', features={'manuallySendReadReceipts': True}) response = self.api.set_configuration(config) self.assertEqual(post.call_count, 1) self.assertEqual(post.call_args[0][0], 'https://api.kik.com/v1/config') self.assertEqual(post.call_args[1]['timeout'], 60) self.assertEqual(post.call_args[1]['auth'], ('mybotusername', 'mybotapikey')) self.assertEqual(post.call_args[1]['headers'], {'Content-Type': 'application/json'}) self.assertEqual( json.loads(post.call_args[1]['data']), { 'webhook': 'https://example.com/incoming', 'features': { 'manuallySendReadReceipts': True } }) self.assertEqual(response, {})
def test_set_configuration(self, post): config = Configuration(webhook='https://example.com/incoming', features={'manuallySendReadReceipts': True}, static_keyboard=SuggestedResponseKeyboard( responses=[TextResponse('foo')])) response = self.api.set_configuration(config) self.assertEqual(post.call_count, 1) self.assertEqual(post.call_args[0][0], 'https://api.kik.com/v1/config') self.assertEqual(post.call_args[1]['timeout'], 60) self.assertEqual(post.call_args[1]['auth'], ('mybotusername', 'mybotapikey')) self.assertEqual(post.call_args[1]['headers'], {'Content-Type': 'application/json'}) self.assertEqual( json.loads(post.call_args[1]['data']), { 'webhook': 'https://example.com/incoming', 'features': { 'manuallySendReadReceipts': True }, 'staticKeyboard': { 'type': 'suggested', 'responses': [{ 'type': 'text', 'body': 'foo' }] } }) self.assertIsInstance(response, Configuration) self.assertEqual(response.webhook, 'https://example.com/incoming') self.assertEqual(response.features, {'manuallySendReadReceipts': True}) self.assertIsInstance(response.static_keyboard, SuggestedResponseKeyboard) self.assertEqual( response.static_keyboard, SuggestedResponseKeyboard(responses=[TextResponse('foo')]))
def test_from_json(self): config = Configuration.from_json({ 'webhook': 'https://mybot.com/incoming', 'features': { 'manuallySendReadReceipts': True }, 'staticKeyboard': { 'type': 'suggested', 'responses': [ { 'type': 'text', 'body': 'foo' } ] } }) self.assertEqual(config.webhook, 'https://mybot.com/incoming') self.assertEqual(config.features, {'manuallySendReadReceipts': True}) self.assertIsInstance(config.static_keyboard, SuggestedResponseKeyboard) self.assertEqual(config.static_keyboard, SuggestedResponseKeyboard( responses=[ TextResponse('foo') ] ))
from flask import Flask, request, Response from kik import KikApi, Configuration from kik.messages import messages_from_json, TextMessage try: from settings import * except ImportError: from settings.example import * app = Flask(__name__) kik = KikApi(BOT_USERNAME, BOT_API_KEY) kik.set_configuration(Configuration(webhook=WEBHOOK)) @app.route('/webhook', methods=['POST']) def incoming(): if not kik.verify_signature(request.headers.get('X-Kik-Signature'), request.get_data()): return Response(status=403) messages = messages_from_json(request.json['messages']) for message in messages: if isinstance(message, TextMessage): kik.send_messages([ TextMessage( to=message.from_user, chat_id=message.chat_id, body=message.body ) ])
profile_picture = user.profile_pic_url if profile_picture is not None: messages_to_send.append( # Another type of message is the PictureMessage - your bot can send a pic to the user! PictureMessage( to=message.from_user, chat_id=message.chat_id, pic_url=profile_picture )) profile_picture_response = "ini dia foto kamuu!" else: profile_picture_response = "ga mirip loh, yaudh lah yaa" messages_to_send.append( TextMessage(to=message.from_user, chat_id=message.chat_id, body=profile_picture_response)) return messages_to_send if __name__ == "__main__": """ Main program """ kik = KikApi('dodebot', '50c8dd0b-3eee-4b6d-a75e-22d1ea3abecf') # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once # or if the configuration changes. In a production setting, you would only issue this call if you need to change # the configuration, and not every time the bot starts. kik.set_configuration(Configuration(webhook='https://a62f7c5e.ngrok.io/incoming')) app = KikBot(kik, __name__) app.run(port=8080, host='127.0.0.1', debug=True)
return location def geoip(): ip = request.headers.get('X-Forwarded-For', request.remote_addr) if ',' in ip: ip = ip.split(',')[0] return geo.get(ip) if config.KIK_BOT_ENABLED: kik_service = KikApi(config.KIK_BOT_USERNAME, config.KIK_BOT_KEY) try: kik_service.set_configuration( Configuration(webhook='https://%s%s' % (config.SERVER_NAME, config.KIK_BOT_WEBHOOK))) except Exception as e: logging.warning(e) else: kik_service = None if config.MICROSOFT_BOT_ENABLED: microsoft_service = BotFrameworkMicrosoft(config.MICROSOFT_BOT_ID, config.MICROSOFT_BOT_KEY) else: microsoft_service = None if config.FACEBOOK_BOT_ENABLED: facebook_service = fbmq.Page(config.FACEBOOK_BOT_KEY) try: facebook_service.show_starting_button("START_PAYLOAD")
if profile_picture is not None: messages_to_send.append( # Another type of message is the PictureMessage - your bot can send a pic to the user! PictureMessage(to=message.from_user, chat_id=message.chat_id, pic_url=profile_picture)) profile_picture_response = "Here's your profile picture!" else: profile_picture_response = "It does not look like you have a profile picture, you should set one" messages_to_send.append( TextMessage(to=message.from_user, chat_id=message.chat_id, body=profile_picture_response)) return messages_to_send if __name__ == "__main__": """ Main program """ kik = KikApi('prodfriend', '958137de-1eac-4b5c-a440-5bc5c36d769a') # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once # or if the configuration changes. In a production setting, you would only issue this call if you need to change # the configuration, and not every time the bot starts. kik.set_configuration( Configuration(webhook='http://bdc639a1.ngrok.io/incoming')) app = KikBot(kik, __name__) app.run(port=8080, host='127.0.0.1', debug=True)
if profile_picture is not None: messages_to_send.append( # Another type of message is the PictureMessage - your bot can send a pic to the user! PictureMessage(to=message.from_user, chat_id=message.chat_id, pic_url=profile_picture)) profile_picture_response = "ini dia foto kamuu!" else: profile_picture_response = "ga mirip loh, yaudh lah yaa" messages_to_send.append( TextMessage(to=message.from_user, chat_id=message.chat_id, body=profile_picture_response)) return messages_to_send if __name__ == "__main__": """ Main program """ kik = KikApi('botmca', 'fffa79e9-afe9-45e4-b2bd-6ec78732b3de') # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once # or if the configuration changes. In a production setting, you would only issue this call if you need to change # the configuration, and not every time the bot starts. kik.set_configuration( Configuration(webhook='https://7c50a1a4.ngrok.io/incoming')) app = KikBot(kik, __name__) app.run(port=8080, host='127.0.0.1', debug=True)
from weather_request import * from wit import Wit bot = Wit(access_token="VOCFYQI6MHUL7CDRMPURE4Z26KJGNL7G") usr_name = 'glooffybot' key = '71981fb3-c57d-43bf-ac84-534120e8857e' weather_key = "396cbf110cc7bd1bd3087f317643a83f" app = Flask(__name__) kik = KikApi(usr_name, key) # this is for the kik server. It sets up the webhook so that kik server can # send messages to the webhook and then incoming function extracts the data # recieved. kik.set_configuration(Configuration(webhook='https://glooffy.herokuapp.com/')) def SendMessage(user, ch_id, msg): # sends a single message kik.send_messages([TextMessage(to=user, chat_id=ch_id, body=msg)]) @app.route('/', methods=['POST']) def incoming(): if not kik.verify_signature(request.headers.get('X-Kik-Signature'), request.get_data()): return Response(status=403) # list of python objects messages = messages_from_json(request.json['messages'])
from flask import Flask, request, Response from kik import KikApi, Configuration from kik.messages import messages_from_json, TextMessage app = Flask(__name__) kik = KikApi("female_lama", "42cd379e-5f1a-4390-881d-955f028221e2") kik.set_configuration( Configuration(webhook="https://22e81a38.ngrok.io/incoming")) live_dict = {} def user_is_admin(username): return username in [ "ilike3pancakes", "oskarsbanana", "YG_Bands_", "vikiid95", "goditee", "BossJordan_g", "Its_Margo_", "yoitscass28" ] def maybe_do_verify(_text_message): if not user_is_admin(_text_message.from_user): return _text_message.body user = _text_message.body.split("verify with me ") if len(user) < 2 or len(user[1]) < 1: return "Please verify with the admin @%s" % _text_message.from_user return "Hello %s, the group admin @%s is asking for verification. Please send a live photo to them using the kik camera to prove that your kik profile is real." % ( user[1], _text_message.from_user)
self.response_messages.append( TextMessage(to=self.message.from_user, chat_id=self.message.chat_id, body=message)) def send_message_with_responses(self, message, responses): text_responses = [] for response in responses: text_responses.append(TextResponse(response)) self.response_messages.append( TextMessage(to=self.message.from_user, chat_id=self.message.chat_id, body=message, keyboards=[ SuggestedResponseKeyboard(responses=text_responses) ])) if __name__ == "__main__": """ Main program """ kik = KikApi('studyhelper', 'be6f061d-69f2-401a-9fad-0a31aa9cac68') # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once # or if the configuration changes. In a production setting, you would only issue this call if you need to change # the configuration, and not every time the bot starts. kik.set_configuration(Configuration(webhook=LISTENING_SERVER + '/incoming')) app = KikBot(kik, __name__) app.run(port=8080, host='127.0.0.1', debug=True)
from flask import Flask, request, Response from kik import KikApi, Configuration from kik.messages import messages_from_json, TextMessage, VideoMessage ##### NEW ##### from config import username, api_key, webhook ##### NEW ##### from giphypop import translate app = Flask(__name__) kik = KikApi(username, api_key) kik.set_configuration(Configuration(webhook=webhook)) ###### def giffy(message): img = translate(message, api_key='dc6zaTOxFJmzC') gif = img.fixed_height.url print(gif) return gif ####### @app.route('/incoming', methods=['POST']) def incoming(): print('coming in here') if not kik.verify_signature(request.headers.get('X-Kik-Signature'),
import json import logging from kik_sql import KikDB import os logging.basicConfig(filename='hangmanlog.log', level=logging.INFO, format="[%(asctime)s] %(message)s") app = Flask(__name__) kik = KikApi('gameofhangman', os.environ['KIK_API_KEY']) Hangman.kik = kik code = kik.create_code( {os.environ['KIK_CODE_KEY']: os.environ['KIK_CODE_VALUE']}) server_url = 'http://' + os.environ['KIK_HOSTNAME'] + ':8080/incoming' kik.set_configuration(Configuration(webhook=server_url)) def logprint(msg, *args): logging.info(msg) for i in args: logging.info(str(i)) print(msg, args) @app.route('/incoming', methods=['POST']) def incoming(): if not kik.verify_signature(request.headers.get('X-Kik-Signature'), request.get_data()): return Response(status=403)
if profile_picture is not None: messages_to_send.append( # Another type of message is the PictureMessage - your bot can send a pic to the user! PictureMessage( to=message.from_user, chat_id=message.chat_id, pic_url=profile_picture )) profile_picture_response = "Here's your profile picture!" else: profile_picture_response = "It does not look like you have a profile picture, you should set one" messages_to_send.append( TextMessage(to=message.from_user, chat_id=message.chat_id, body=profile_picture_response)) return messages_to_send if __name__ == "__main__": """ Main program """ kik = KikApi('bear.bot1', 'a7343fdc-e454-4b05-83d2-70fc8bb531f7') # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once # or if the configuration changes. In a production setting, you would only issue this call if you need to change # the configuration, and not every time the bot starts. kik.set_configuration(Configuration(webhook='https://38cc2287.ngrok.io/')) app = KikBot(kik, __name__) app.run(port=9999, host='localhost', debug=True) #app.run(port=4040, host='127.0.0.1')
"[{bot_username}] Could not load custom module: custom_modules.{custom_module} ... - ignoring" .format(custom_module=custom_module_name, bot_username=bot_username)) # prepare database if custom_module is not None and hasattr(custom_module, "ModuleCharacterPersistentClass"): db_class = custom_module.ModuleCharacterPersistentClass( default_config, bot_username) else: db_class = CharacterPersistentClass(default_config, bot_username) del db_class kik_api = KikApi( bot_username, default_config.get("BotAuthCode", "abcdef01-2345-6789-abcd-ef0123456789")) LazyKikUser.kik_api = kik_api # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once # or if the configuration changes. In a production setting, you would only issue this call if you need to change # the configuration, and not every time the bot starts. kik_api.set_configuration( Configuration(webhook="{}:{}/incoming".format( default_config.get("RemoteHostIP", "www.example.com"), default_config.get("RemotePort", "8080")))) print("[{bot_username}] Debug URL: {host}:{port}/debug".format( bot_username=bot_username, host=default_config.get("RemoteHostIP", "www.example.com"), port=default_config.get("RemotePort", "8080"))) print("[{bot_username}] Started: {now:%d.%m.%Y %H:%M:%S}".format( bot_username=bot_username, now=datetime.now()))
"manuallySendReadReceipts": False, "receiveReadReceipts": True, "receiveDeliveryReceipts": False, "receiveIsTyping": False } staticKeyboard = SuggestedResponseKeyboard(responses=[ TextResponse('BENCHMARK ANALYSIS'), TextResponse('PROBE ANALYSIS'), TextResponse('INACTIVE ANALYSIS'), TextResponse('HELP') ]) kik.set_configuration( Configuration(webhook='WEBHOOK', features=afeatures, static_keyboard=staticKeyboard)) banlist = "" #list of users to have privadged access to reset benchmark adminlist = {} #-----------------Returns Keyboard based on if user in in adminlist or not def SetKeyboard(user): if user in adminlist: Keyboard = [ SuggestedResponseKeyboard(to=user, hidden=True, responses=[
profile_picture = user.profile_pic_url if profile_picture is not None: messages_to_send.append( # Another type of message is the PictureMessage - your bot can send a pic to the user! PictureMessage(to=message.from_user, chat_id=message.chat_id, pic_url=profile_picture)) profile_picture_response = "Here's your profile picture!" else: profile_picture_response = "It does not look like you have a profile picture, you should set one" messages_to_send.append( TextMessage(to=message.from_user, chat_id=message.chat_id, body=profile_picture_response)) return messages_to_send if __name__ == "__main__": """ Main program """ kik = KikApi('BOT_USERNAME_HERE', 'BOT_API_KEY_HERE') # For simplicity, we're going to set_configuration on startup. However, this really only needs to happen once # or if the configuration changes. In a production setting, you would only issue this call if you need to change # the configuration, and not every time the bot starts. kik.set_configuration(Configuration(webhook='WEBHOOK_HERE')) app = KikBot(kik, __name__) app.run(port=8080, host='127.0.0.1', debug=True)