<commit_before>.. _user:

User Guide
==========

Ready to get started? This page gives an overview of how to install and use kik

Installation
------------

You can install the library though pip, either from the command line::

    $ pip install kik

or add the following line to your project's requirements.txt file:

.. parsed-literal::

    kik==\ |version|

Example Server
--------------

Here is a minimal echo bot using Flask

.. code-block:: python
    :linenos:

    from flask import Flask, request, Response

    from kik import KikApi
    from kik.messages import messages_from_json, TextMessage

    app = Flask(__name__)
    kik = KikApi(BOT_USERNAME, BOT_API_KEY)


    @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:
            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__":
        app.run(port=8080, debug=True)

The API Client
--------------

The core of the library is the :class:`KikApi<kik.KikApi>` class, which is used to send requests to the Kik API.
The client needs to be instantiated with your bot's username and API key:<commit_msg>Fix up mistake in the example bot docs.<commit_after>.. _user:

User Guide
==========

Ready to get started? This page gives an overview of how to install and use kik

Installation
------------

You can install the library though pip, either from the command line::

    $ pip install kik

or add the following line to your project's requirements.txt file:

.. parsed-literal::

    kik==\ |version|

Example Server
--------------

Here is a minimal echo bot using Flask

.. code-block:: python
    :linenos:

    from flask import Flask, request, Response

    from kik import KikApi
    from kik.messages import messages_from_json, TextMessage

    app = Flask(__name__)
    kik = KikApi(BOT_USERNAME, BOT_API_KEY)


    @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:
            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__":
        app.run(port=8080, debug=True)

The API Client
--------------

The core of the library is the :class:`KikApi<kik.KikApi>` class, which is used to send requests to the Kik API.
The client needs to be instantiated with your bot's username and API key:
{'fraction_non_alphanumeric': 0.11053276178812002, 'fraction_numerical': 0.00612369871402327, 'mean_word_length': 2.2123893805309733, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '617269', 'n_tokens_mistral': 941, 'n_tokens_neox': 877, 'n_words': 302}