I am trying to setup an opening chatting message on my kik bot using Python, and can not seem to find an answer to this question. The StartChattingMessage()
is what I am supposed to use to send out the first message.
Here is my code below, ideally when a user responds to your bot, you are able to send out any message by obtaining the chat_id
and from_user
from the JSON payload, but before the user enters in any text, I would like to display a welcome message to the user, without the user having to say anything at all. But in order to send any message at all you need a chat_id
and a from_user
values.
# Kik bot messenger using Python 3, Flask, Gunicorn and Jinja 2
from flask import Flask, request, Response
import os
from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage,StartChattingMessage, ScanDataMessage, LinkMessage, \
DeliveryReceiptMessage, ReadReceiptMessage, VideoMessage
app = Flask(__name__)
kik = KikApi("BOT_USERNAME", "BOT_API_KEY")
config = Configuration(webhook='WEBHOOK')
kik.set_configuration(config)
@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)
messages = messages_from_json(request.json['messages'])
for message in messages:
kik.send_messages([
TextMessage(
to=message.from_user,
chat_id=message.chat_id,
body="Hey Welcome to my chat bot !"
)]
)
return Response(status=200)
@app.route("/", methods=['GET'])
def hello():
return "<h1> Hello Welcome To My Kik Bot Messenger, Check out my bot at @afischbacher95 </h1>"
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)