ChatWars API

From ChatWars Wiki
Jump to: navigation, search

ChatWars API

The ChatWars API is the official way to interact with the game programmatically. Possible actions are:

  • receive (listen to)
  • interact with player accounts (needs authorization)
    • request player profile / stock information
    • retrieve and make payments (pouches only)
    • make buy requests in name of player on the exchange (wtb/sniping)
    • request player's (craftbook)
    • request player's (guild) (excluding member list)

Technology

The API is based on AMQP, a message queuing protocol. The used implementation is RabbitMQ.

API access

Request for API access via email. You have to specify an "application" name (username), which queues you want to listen to and which grants you want to have. You get a username and a password. Requests may take some time to be fulfilled.

Depending on your request there are queues created for your username. Let your telegram name be john and your app name be myapp, then the created username might look like john_myapp and then the queues are named like john_myapp_deals, john_myapp_yellow_pages or john_myapp_i.

You don't have to declare any queues yourself or bind them to fanout exchanges. Trying so will result in error. Just consume your individual queues.

Pseudo code listening on deals exchange:

// create connection with properties:
// useSslProtocol = true
// host = "api.chatwars.me"
// port = 5673
// virtualhost = "/"
connection := createAMPQConnection( "amqps://api.chatwars.me:5673/", "john_myapp", "passwordViaChatwarsfeedbackbot")

// get a channel from the connection
channel := connection.createChannel()

// a consumer receives the messages from the queue; programm logic is going to be there
consumer := createNewMyConsumer()

// setting autoAck = true means every message is immediately acknowledged when a consumer recieves it
// set autoAck = false if you want the server to redeliver the messages on failure, but you HAVE TO acknowledge every message within consumer manually then!
autoAck := true

// attach consumer to queue of fanout exchange deals (everything is already declared and bound)
channel.basicConsume("john_myapp_deals", autoAck, consumer))

// keep programm running forever ...

Further help