#[Phone] - Messages not showing up when using server export

1 messages · Page 1 of 1 (latest)

daring lance
#

Product: LB-Phone
Issue: Messages not showing up in chat until you close out and re-open the conversation.
When: When using the server export to send messages to a user
How to recreate: Open conversation with specified phone number, have script send user message from specified number
Does this happen for everyone: Everyone
Attachment: https://medal.tv/games/gta-v/clips/jC67At130_S56TQWF?invite=cr-MSxwM3ksNzA4NzgzMTEs
Version: Phone - 2.1.12
Framework: QB
Has this bug appeared more than once? If so, how often?: Every time

worldly sonnet
#

Could you also provide the code snippet used for the export along with the data concerning each of the variables ?

daring lance
#
local API_KEY = "###"
local OPENAI_URL = "https://api.openai.com/v1/chat/completions"
local playerConversations = {}

AddEventHandler("lb-phone:messages:messageSent", function(message)
    print("[DEBUG] Message received:", json.encode(message))

    if not message or not message.sender or not message.recipient or not message.message then
        print("[ERROR] Invalid message structure")
        return
    end

    if message.recipient ~= "6269132517" then
        print("[DEBUG] Message is not for 6269132517. Ignored.")
        return
    end

    print("[INFO] Message sent to sketchy individual by:", message.sender)

    if not playerConversations[message.sender] then
        playerConversations[message.sender] = {
            { role = "system", content = "You are a shady dealer negotiating drug prices. Respond cryptically and suspiciously in a way that fits a roleplay scenario." }
        }
    end

    table.insert(playerConversations[message.sender], { role = "user", content = message.message })

    local requestData = {
        model = "gpt-4o-mini",
        messages = playerConversations[message.sender],
        max_tokens = 100,
        temperature = 0.7
    }

    print("[DEBUG] OpenAI Request Data:", json.encode(requestData))

    PerformHttpRequest(OPENAI_URL, function(statusCode, response, headers)
        print("[DEBUG] OpenAI Response Status Code:", statusCode)
        print("[DEBUG] OpenAI Response Body:", response)

        if statusCode == 200 then
            local decodedResponse = json.decode(response)
            if decodedResponse and decodedResponse.choices and decodedResponse.choices[1] then
                local aiResponse = decodedResponse.choices[1].message.content
                print("[INFO] Dealer Response:", aiResponse)

                table.insert(playerConversations[message.sender], { role = "assistant", content = aiResponse })

                local channelId = message.channelId
                if type(channelId) == "number" then
                    channelId = tostring(channelId)
                end

                exports["lb-phone"]:SendMessage("6269132517", message.sender, aiResponse, nil, nil, channelId)
                print("[INFO] AI Response sent successfully!")
            else
                print("[ERROR] Invalid response format from OpenAI")
            end
        else
            print("[ERROR] Failed to reach OpenAI API, Status Code:", statusCode)
        end
    end, "POST", json.encode(requestData), {
        ["Authorization"] = "Bearer " .. API_KEY,
        ["Content-Type"] = "application/json"
    })
end)

RegisterNetEvent("clearConversationHistory")
AddEventHandler("clearConversationHistory", function(playerId)
    playerConversations[playerId] = nil
    print("[INFO] Cleared conversation history for player:", playerId)
end)
#

pulled the key, but that should give an idea of what I'm using it for

worldly sonnet
#

Thanks 👍

daring lance
#

Update on this, was doing further testing and the issue just stopped?