1

I just started working on Kik API to make my very own Kik bot. I need to figure out a way to know the chat id of the user to whom I'll send replies i.e. the user who is already subscribed to me and is sending me messages. This is the code that I'm using :

from kik import KikApi, Configuration
from kik.messages import messages_from_json, TextMessage
import requests
import json
kik = KikApi('bot_username','API_key')
kik.send_messages([
    TextMessage(
        to='subscribed_user',
        chat_id='',
        body='Test'
     )
 ])

Please point me in the right direction. Thanks!

Shashwat Siddhant
  • 411
  • 2
  • 5
  • 17

1 Answers1

0

When a user initiates a chat with a bot, it automatically creates a unique chat id that can be used to respond to it. You need to store this chat id and set it on your outgoing message.

kik.send_messages([
    TextMessage(
        to='subscribed_user',
        chat_id='<chat_id>',
        body='Test'
     )
 ])
Alvin Reyes
  • 710
  • 1
  • 8
  • 24
  • How do I store the chat id? – Shashwat Siddhant Jun 29 '17 at 22:17
  • 1
    What technology stack / framework or toolkit are you using to create Kik bots? It needs to be stored within the conversation flow (like a session store) in order for you to use it. – Alvin Reyes Jul 24 '17 at 15:00
  • I am using Python 2.7 for this and all the above mentioned Kik libraries. I still can't figure out a way to get the chat id of the user I want to send message to. – Shashwat Siddhant Jul 25 '17 at 03:59
  • You can store all responses on a database storage (nosql or rdbms). You can then use this to store the chatId and use it for subsequent chat responses. We can do a wizpert session so that I can show you, but im not sure if its allowed here. – Alvin Reyes Aug 08 '17 at 12:54