project-error / npwd

NPWD is a FiveM phone resource written entirely in TypeScript and React.
https://projecterror.dev
Other
351 stars 277 forks source link

emitMessage export not working properly: Trying to send a message using the export returns an error #740

Closed PlouffeLuL closed 2 years ago

PlouffeLuL commented 2 years ago

Development Issue

Unsure

Phone Version

1.2.96 (latest avaible when i last tested it)

Issue Description

Using this function

function SendMessage(playerId, message)
    local phoneNumber = exports.ooc_core:getPlayerFromId(playerId).phone_number
    local messageData = {senderNumber = "666-555-4455", targetNumber  = tostring(phoneNumber), message = message}

    print(("Sending message '%s' to number '%s' from number '%s'"):format(messageData.message, messageData.targetNumber, messageData.senderNumber))

    exports.npwd:emitMessage(messageData)
end

RegisterCommand("textme", function(s)
    SendMessage(s, "Dicks")
end)

Returns this log (that should be expected according to mojito)

[         script:npwd] Failed to emit message. Error: Cannot read properties of undefined (reading 'id')

According to the information i have the message should still be sent anyway but i also get this error

[         script:npwd] [NPWD] [player] [error]: Failed to fetch identifier from phone number for 666-555-4455, error: Cannot read properties of undefined (reading 'state_id')

This is my npwd config

{
  "PhoneAsItem": {
    "enabled": true,
    "exportResource": "ooc_core",
    "exportFunction": "hasPhone"
  },
  "general": {
    "useResourceIntegration": true,
    "toggleKey": "f1",
    "toggleCommand": "phone",
    "defaultLanguage": "en"
  },
  "profanityFilter": {
    "enabled": false,
    "badWords": ["esx"]
  },
  "database": {
    "useIdentifierPrefix": false,
    "playerTable": "users_characters",
    "identifierColumn": "state_id",
    "identifierType": "",
    "profileQueries": true,
    "phoneNumberColumn": "phone_number"
  },
  "debug": {
    "level": "error",
    "enabled": true,
    "sentryEnabled": true
  }
}

The phone it self seems to works properly, i can send messages to other players and such but the export dosent seem to be willing to work.

Issue Reproduction

Use the export.

Evidence

I took a video showing the phone working properly, the code line used and the error on the server console.

https://streamable.com/kvxzcf

LiamDormon commented 2 years ago

I can't reproduce this problem

LiamDormon commented 2 years ago

The first error log is expected when trying to fetch a number which doesn't exist, however the second log I can't reproduce

PlouffeLuL commented 2 years ago

Thats why i took the video cause i knew at some point people would think im doing something wrong but i cant figure out what is wrong with what im doing.

Could this be cause because im not using the classic "Steam" identifier and "Users" table in database ? Just throwing that out there.

I really want to get it to work but i just dont get it. If i had any ts skills i would try to find a solution but im terrible at ts.

If you want i can do a share screen but i assume the video should be enough..