问题
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.
回答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.
来源:https://stackoverflow.com/questions/39006692/deploying-kik-bot-to-heroku-not-working