1

I've been trying to deploy my kik api to heroku, but it just isn't working. I've set up my procfile, my requirements.txt file, my runtime.txt file, and it shows up on my machine as running fine. However, when I open the kik app on my phone and try to message the bot, the messages aren't sent and it is not echoing my message. By Using ngrok as a webhook, I was able to get the bot to work and echo the messages just fine. However, when I tried deploying to heroku, it didn't work at all. For reference, the kik bot is written using flask and the kik api, here is my code

from flask import Flask, request, Response
import os 
from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage

app = Flask(__name__)
BOT_USERNAME = os.environ['BOT_USERNAME'] 
BOT_API_KEY= os.environ['BOT_API_KEY']
kik = KikApi(BOT_USERNAME, BOT_API_KEY)
config = Configuration(webhook=os.environ['WEBHOOK'])
kik.set_configuration(config)
@app.route('/', 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
                    )
            ])

    return Response(status=200)

if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    print('HI') 
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

Here is my requirements.txt

Flask==0.11.1
kik==1.1.0
gunicorn==19.6.0

Here is my runtime.txt

python-2.7.12

Here is my procfile

web: python bot.py

I set up the webhook variable to be the heroku URL. When I run the app locally, it seems to be running just fine.

Heroku local app

Any help is greatly appreciated.

Bob
  • 129
  • 2
  • 9
  • what do the logs say? – lonewaft Aug 17 '16 at 21:58
  • @lonewaft I can screenshot the log, [heroku log](http://i67.tinypic.com/be81z9.png). It looks like everything is fine. I just wish there was a way to debug it or see why the bot isn't responding locally. – Bob Aug 17 '16 at 23:09
  • Those are just the logs for deployment, what about while it's running on the server? – lonewaft Aug 17 '16 at 23:10
  • @lonewaft [[Local server log](https://s3.postimg.org/681q01a03/Screen_Shot_2016_08_17_at_6_13_42_PM.png)] This is all that shows up when I run it locally, even when I've made a POST by messaging the bot on my phone. – Bob Aug 17 '16 at 23:15

1 Answers1

1

I figured out the issue. I had set the wrong environmental variables for my heroku deployment, so it threw a keyerror because it couldn't find the key and stopped the process.

Bob
  • 129
  • 2
  • 9