If for some reason you can't work with DLL library or something you need is missing in the list of integrations, you can work with MyChat Server directly via network sockets. A lot of programming languages and systems allow doing so.

 

Network data sent in a single-byte ASCII encoding. Each line ends with the symbol CRLF (#13#10), 2 bytes, no internal delimiters in the string, all data "glued up" one by one.

 

The scheme of any command in MyChat Intergration API has four stages:

 

  1. Connection to the server.
  2. Sending a command in JSON FORMAT.
  3. Getting result of JSON work.
  4. Disconnection from the server.

 

For example, JSON object for sending a private message (MCIAPI_CS_SendPrivateMessage):

SendPrivateMessage JSON

{
  "UserTo"   : 15427,
  "UserFrom" : 0,
  "Msg"      : "Hello",
  "hash"     : "",
  "APIStype" : "customapi",
  "ServerKey" : "iddqd"
}


How to send a command and get explanation of what happened?


Work in a synchronous mode (blocked mode); commands of sending and reading go strictly in order.

It looks like this on a pseudo-code:


try
  1. Connect to IP/port
  2. writeln "mc2023.4.0"
  3. writeln "{"Secured":""}
  4. readln (sc_hello)
  5. writeln MagicPacket + cs_integration_api + iFlag + MCIAPI_CS_SendPrivateMessage + JSON
  6. readln (JSON, server reply)
except
  Warning!!! Network Error (SOCKET) number and description
end;


Constants you need


Constant

Value

Size in bytes

CRLF

#13#10

2 (text string)

MCIAPI_CS_SendPrivateMessage

"0002"

4 (text string)

MagicPacket

#23#6

2

cs_integration_api

"0077"

4 (text string)

iFlag

30

2

 

See also

C#

Example for Delphi XE3

Example for Java

Python