Difference between revisions of "ChatWars API"
(The ChatWars API is the official way to interact with the game programmatically.) |
(added pseudo code; minor changes) |
||
Line 1: | Line 1: | ||
= ChatWars API = | = ChatWars API = | ||
− | The ChatWars API is the official way to | + | The ChatWars API is the official way to interact with the game programmatically. |
+ | Possible actions are: | ||
*receive (listen to) | *receive (listen to) | ||
**stock exchange updates (offers/deals) | **stock exchange updates (offers/deals) | ||
Line 16: | Line 17: | ||
Request for API access via [https://t.me/ChatWarsFeedbackBot @ChatWarsFeedbackBot]. 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. If you didn't get feedback within a day, request again. | Request for API access via [https://t.me/ChatWarsFeedbackBot @ChatWarsFeedbackBot]. 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. If you didn't get feedback within a day, request again. | ||
− | You don't have to declare any queues or bind them to | + | Depending on your request there are queues created for your username. Let your telegram name be <code>john</code> and your app name be <code>myapp</code>, then the created username might look like <code>john_myapp</code> and then the queues are named like <code>john_myapp_deals</code>, <code>john_myapp_yellow_pages</code> or <code>john_myapp_i</code>. |
+ | |||
+ | '''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 == | == Further help == |
Revision as of 19:55, 21 May 2018
ChatWars API
The ChatWars API is the official way to interact with the game programmatically. Possible actions are:
- receive (listen to)
- stock exchange updates (offers/deals)
- current lowest offers per item (sex_digest)
- list of open shops (yellow_pages)
- interact with player accounts (needs authorization)
- request player profile / stock information
- retrieve and make payments (pouches only)
- make buy requests in name of player (wtb/sniping)
Technology
The API is based on AMQP, a message queuing protocol. The used implementation is RabbitMQ.
API access
Request for API access via @ChatWarsFeedbackBot. 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. If you didn't get feedback within a day, request again.
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
- Developers Castle Chat (only for real developers, sometimes rude.)
- ChatWars API updates channel
- CW API v0.6