2-Way Chat with Mobile Users

See files for this Use Case on GitHub here

Mobile users can communicate with each other by using Route4Me's notification system.

Description

The Route4Me API allows you to send a specific message directly to the Activity Feed. Also, you can read and filter logged messages. Using these features, the dispatcher can see where all users are located on a real-time map, and then they can communicate with each of the drivers using 2-way chat.

Solution

Setting of a Real Time Callback

Real-time callbacks permit third-party systems to receive notifications about every system and driver event, such as when a user manually makes a notification or when the system automatically logs a driver entering a Dynamic Geofence (TM).

The callback is set at the account owner user level, so all activities detected by sub-users and sub-drivers are also sent to the callback URL.

Note
In the field "Callback URL", you should enter your own endpoint URL, which will receive and process notifications from Route4Me.

Optimization Parameters and addresses

Let's choose the Single Driver Round Trip option for this Use Case. Here are the parameters for this optimization:

ParameterTypeDescriptionHTTP method
api_keystringAPI KEY of the userGET
redirectintegerIf equal to 1, will be redirected, if 0 - notGET
addressesarrayValid JSON array of Address objects. Click here to see the JSON SchemaPOST
parametersRoute ParametersValid JSON string of RouteParameters object. Click here to see the JSON SchemaPOST

You can see the addresses on the map as:

Create an Optimization

The cURL example below shows you how to create new optimized routes for this Use Case:

ParameterTypeDescription
api_keystringAPI KEY of the user
input dataPOST dataValid JSON object string. Click here to see the JSON Schema
1 @ECHO OFF
2 
3 :: Single Driver Round Trip
4 ::See video tutorial here: http://support.route4me.com/route-planning-help.php?id=manual0:tutorial2:chapter1:subchapter1
5 
6 SET URL=https://www.route4me.com/api.v4/optimization_problem.php
7 SET apikey=11111111111111111111111111111111
8 
9 ECHO ON
10 
11 curl -o file1.txt -g -X POST -k -d "@single_driver_round_trip_data.json" "%url%?api_key=%apikey%"
12 
13 timeout /t 30

You can expect an Optimization Problem (see link), which has generated a route already.

View the Optimization details

You can get more details from the newly created Optimization Problem.

The endpoint: https://www.route4me.com/api.v4/optimization_problem.php

HTTP Parameters

AttributeTypeDescriptionHTTP
method
api_keystringAPI KEY of the userGET
optimization_problem_idstringOptimization problem IDGET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/optimization_problem.php
4 SET apikey=11111111111111111111111111111111
5 SET optprobid=69E1F364F7D2B78FBE9FFB37A0755CEB
6 
7 ECHO ON
8 curl -o file1.txt -g -X GET -k "%URL%?api_key=%apikey%&optimization_problem_id=%optprobid%"
9 
10 timeout /t 30

See sample RESPONSE JSON data here

In the RESPONSE you can see an array of the addresses, which belong to one round trip route.

Details of the Optimized Route

You can get more details of this route.

The endpoint: https://www.route4me.com/api.v4/route.php

HTTP Parameters

AttributeTypeDescriptionHTTP
method
api_keystringAPI KEY of the userGET
route_idstringRoute IDGET
route_path_outputstringIf equal to 'Poitns', you'll get an array of the path points to next addressGET


1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/route.php
4 SET apikey=11111111111111111111111111111111
5 SET routeid=EDE99139F62A036E9651D4A2AD168E81
6 SET rpo=Points
7 
8 ECHO ON
9 
10 curl -o file1.txt -g -k -X GET "%url%?route_id=%routeid%&api_key=%apikey%&route_path_output=%rpo%"
11 
12 timeout /t 30

See sample RESPONSE JSON data here

Note
In the RESPONSE you can see the array of the fields path_to_next and use them to draw routes on a map, exactly as they generated by Route4Me API.

You can draw the generated round trip route as:

Compare it to the drawing of the official Route4Me website:

Log specific message into activity feed

You can log a message directly to the activity feed.

The endpoint: https://www.route4me.com/api.v4/activity_feed.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
activity_type string Should be "user_message" in this use case POST
activity_message string A text message to be logged into activity feed POST
route_id string Route ID POST


You can prepare input JSON data for this step (see input JSON file here)

{
"activity_type": "user_message",
"activity_message": "Hello David I'm dispetcher",
"route_id": "EDE99139F62A036E9651D4A2AD168E81"
}

Now, send the message to the Activity Feed:

1 @ECHO OFF
2 
3 SET url=https://www.route4me.com/api.v4/activity_feed.php
4 SET apikey=11111111111111111111111111111111
5 
6 ECHO ON
7 
8 :: The example refers to sending a message directly to the Activity Feed
9 
10 curl -o file1.txt -g -k -X POST -H "Content-Type: application/json" -d"@send_user_message_data.json" "%url%?api_key=%apikey%"
11 
12 timeout /t 30

You'll get this RESPONSE:

{"status":true}

Read a message from the activity feed

If you have your own endpoint URL for receiving notifications from Route4Me and you've already indicated it in your account as described above, just enter this address in any browser's address field and you'll then be able to read your messages.

But you can read the messages programmatically as well.

The endpoint: https://www.route4me.com/api/get_activities.php

HTTP Parameters

Attribute Type Description HTTP
method
api_key string API KEY of the user GET
activity_type string Should be "user_message" in this use case GET
route_id string Route ID GET


Note
Indication of the route_id parameter is optional - without it you'll get user_message type notifications in your account.
1 @ECHO OFF
2 
3 :: You should insert real test data and your API key for accurate testing
4 
5 SET url=https://www.route4me.com/api/get_activities.php
6 SET apikey=11111111111111111111111111111111
7 SET act_type=user_message
8 SET route_id=EDE99139F62A036E9651D4A2AD168E81
9 
10 ECHO ON
11 curl -o file1.txt -g -k -X GET "%URL%?api_key=%apikey%&activity_type=%act_type%&route_id=%route_id%"
12 
13 timeout /t 30

See sample RESPONSE JSON data here