Skip to content
Ryan Brideau edited this page Jul 31, 2016 · 4 revisions

As of #2019, webhooks have been implemented into PokemonGo-Map. Using these webhooks are simple, and opens up a new realm of possibilities for over almost anything related to PokemonGo-Map.

How Do PokemonGo-Map Webhooks Work?

Every time an event occurs (e.g. a Pokemon spawns) a POST request will be sent to a provided URL containing information about that event. A developer may create a listener in whatever language they feel most comfortable in (it just has to handle incoming connections, after all) and do certain things when information from the webhook is received. For example, a developer would be able to wait for a Dragonite to spawn, then play a loud alarm throughout the house and flash the lights in order to get their attention. All of this could be done without even the slightest touch to the internal PokemonGo-Map code, so there's no risk to break anything.

Types of Webhooks

At the moment, only Pokemon Spawn webhooks are available. More webhooks should be on the way! If you're a developer, feel free to contribute by creating some more webhooks.

Name Notes
pokemon Emitted every time a Pokemon spawns.
gym (planned) Emitted when finding a gym.
pokestop (planned) Emitted when finding a pokestop.
pokestop_lured (planned) Emitted every time a Pokestop is lured.
gym_defeated (planned) Emitted every time a Gym is defeated (prestige changes)
gym_conquered (planned) Emitted every time the owner of a Gym is changed

Webhook Data

The POST request made by PokemonGo-Map will contain the following data for each webhook type:

pokemon

{
    "type": "pokemon",
    "message": {
        "encounter_id": {{encounter id}},
        "spawnpoint_id": {{spawnpoint id}},
        "pokemon_id": {{pokemon id}},
        "latitude": {{spawn latitude}},
        "longitude": {{spawn longitude}},
        "disappear_time": {{disappear timestamp}}
    }
}

Configuring Webhooks

Add -wh http://my-webhook/location argument when starting Pokemon Go Map (runserver.py) to define the location of your webhook. You can add this argument multiple times with different webhook locations to define multiple webhooks.

Example Implementation in Node

The following is a basic node server that can be used to receive and log events on port 9876:

var express = require('express');
var bodyParser = require("body-parser");

var app = express();
app.use(bodyParser.urlencoded({extended : true}));
app.use(bodyParser.json());

var server = require('http').Server(app);
var port = process.env.PORT || 9876;

server.listen(port, function (err) {
  console.log('Running server on port ' + port);
});

app.post('/', function(req, res) {
    console.log(req.body.message);
    console.log(req.body.type)
});

To use this, PokemonGo-Map would be run with the following parameters:

python runserver.py -a ptc -u [username] -p [password] -l "Location or lat/lon" -st 15 -k [google maps api key] -wh http://localhost:9876