Live Helper Chat support forum.. Forum is locked. New place for questions - Github Discussions

You are not logged in.

Announcement

#1 2017-05-14 21:19:33

alex43210
Member
Registered: 2017-05-14
Posts: 11

Operator chat not updated

I have some python script that translate messages from messengers to livehelperchat (why now just connect with operator in messenger? At least because I have some plans about bot usage - so I'll need ability to work with operator and bot and switch between them).

So, here mine code:

[== Undefined ==]
import json
import time
import requests
from support_messenger_connector import BaseSupportChat


class LiveHelperChatError(Exception):
    pass


class LiveHelperChat(BaseSupportChat):
    """
    Livehelperchat client (for https://livehelperchat.com/ and their custom installations)
    """
    def __init__(self, base_path, departament_id):
        """
        Initialize
        :param base_path: base URL (e.g. http://127.0.0.1 for local copy)
        :type base_path: str
        :param departament_id: departament id
        :type departament_id: int
        """
        self.base_path = base_path
        self.departament_id = departament_id

    def _now(self):
        return int(time.time())

    def _validate_response(self, response, validate_json=True):
        if response.status_code != 200:
            raise LiveHelperChatError(response.text)
        if validate_json:
            if json.loads(response.text).get("error", "f") not in ["f", "false"]:
                raise LiveHelperChatError(response.text)

    def _get_captcha(self, timestamp):
        url = "{0}/captcha/captchastring/form/{1}".format(self.base_path, timestamp)
        response = requests.get(url)
        self._validate_response(response)
        return json.loads(response.text)["result"]

    def initialize_session(self, username, message):
        """
        Initialize new session
        :param username: user name
        :type username: str
        :param message: initial message
        :type message: str
        :return: chat session id
        :rtype: str
        """
        now = self._now()
        captcha = self._get_captcha(now)
        params = {
            "Username": username,
            "Email": "***.noreply",
            "Question": message,
            "DepartamentID": self.departament_id,
            "r": None,
            "operator": 0,
            "StartChat": 1,
            "captcha_{0}".format(captcha): now,
            "tscaptcha": now
        }
        url = "{0}/chat/startchat".format(self.base_path)
        headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
        }
        response = requests.post(url, params, headers=headers)
        self._validate_response(response, False)
        location = response.history[0].headers['Location'].split('/')
        chat_id = "{0}/{1}".format(location[-2], location[-1])
        return chat_id

    def send_message(self, chat_id, message):
        """
        Send user message to session
        :param chat_id: chat session id
        :type chat_id: str
        :param message: message
        :type message: str
        """
        url = "{0}/chat/addmsguser/{1}".format(self.base_path, chat_id)
        params = {
            "msg": message
        }
        response = requests.post(url, params)
        self._validate_response(response)

    def is_activated(self, chat_id):
        """
        Is chat session active?
        :param chat_id: chat session id
        :type chat_id: str
        :return: active flag
        :rtype: bool
        """
        now = self._now()
        url = "{0}/chat/checkchatstatus/{1}".format(self.base_path, chat_id)
        params = {
            "_": now
        }
        response = requests.get(url, params)
        self._validate_response(response)
        response_data = json.loads(response.text)
        return response_data["activated"] == "true" and not (response_data.get('closed', False) or
                                                             response_data.get('blocked', False))

    def get_new_messages(self, chat_id, previous_message_id=None):
        """
        Get new messages from chat session (if exists)
        :param chat_id: chat session id
        :type chat_id: str
        :param previous_message_id: previous message id or None
        :type previous_message_id: int|NoneType
        :return: newest message id (or None) and messages (or empty array)
        :rtype: (int|NoneType, list[str])
        """
        if previous_message_id is None:
            previous_message_id = 0
        chat, subchat = chat_id.split('/')
        url = "{0}/chat/syncuser/{1}/{2}/{3}".format(self.base_path, chat, previous_message_id, subchat)
        params = {
            "_": self._now()
        }
        response = requests.get(url, params)
        self._validate_response(response)
        response_data = json.loads(response.text)
        if response_data['message_id'] == 0:
            return None, []
        else:
            last_id = response_data['message_id']
            html = response_data['result']
            individual_message_codes = list(map(
                lambda code: code.split("</span>")[1].split("</div>")[0],
                html.split("</div><div class=\"message-row response\"")
            ))
            return last_id, individual_message_codes

When I works with local installation - it succesfully sends messages between operator and user.
I used version from https://github.com/LiveHelperChat/livehelperchat (version - 2.62). Locally - it works.

But when I switched to https://testsupportmz.livehelperchat.com - I had next problem:
- it sucesfully sends message to operator
- but in operator chat - new messages now showed (also, nothing in chrome javascript console and network tab)
- and when I update operator chat window or send new message - all user messages shows

So - what can be source of this error?

Offline

#2 2017-05-14 21:25:57

PeopleInside
Administrator
From: Italy
Registered: 2014-04-10
Posts: 4,046
Website

Re: Operator chat not updated

Hi alex43210,
welcome in the live helper chat forum and thank you for your post!

Live helper chat hosted is a different version respect the self-hosted version who can be a more updated and advanced version.
For support on the hosted version you should contact the commercial support... if your plane is not free,
contact info here: https://livehelperchat.com/support-13c.html

If your plane is free I think cannot be much support about this issue,
I AM not able to provide support on the hosted version.

So please, if you have any plane of the hosted version I should invite you to contact the support.
The forum is the place where ask limited free support most for the self hosted version.
Thank you!  tongue

I hope this help you.
Please be patient for the reply, can take some time... as the support are very busy.


lol PeopleInside - Live helper chat - free limited forum support!
wink For commercial support or GitHub [see FAQ here]
ops If you want to support this open source project, just donate [see support page]
glasses Something wrong with the forum? [contact a superhero]

Offline

Board footer