Skip to content

Commit

Permalink
use OpenDefaultApp instead of ActiveRoute.Directions (microsoft#1443) (
Browse files Browse the repository at this point in the history
  • Loading branch information
xieofxie authored and ryanisgrig committed Jul 25, 2019
1 parent 1f606af commit 38faf40
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 50 deletions.
32 changes: 6 additions & 26 deletions docs/reference/skills/pointofinterest.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,22 @@ LUIS models for the Skill are provided in .LU file format as part of the Skill.
|KEYWORD| Simple entity matching point of interest keywords and categories |
|ROUTE_TYPE| Phrase list entity mapping route descriptors to `eco`,`fastest`,`shortest`,`thrilling`|
|number| Prebuilt entity|
|geographyV2| Prebuilt entity|

## Event Responses

The Point of Interest Skill surfaces a users request to navigate to a new destination through an event returned to the client. The event is called `ActiveRoute.Directions" has contains a series of Points for the Route along with a summary of the route information. A simplified example is shown below
The Point of Interest Skill surfaces a users request to navigate to a new destination through an event returned to the client. The event is called `OpenDefaultApp` which contains the coordinates of the destination. The format is shown below:

```json
{
"name": "ActiveRoute.Directions",
"name": "OpenDefaultApp",
"type": "event",
"value": [
{
"points": [
{
"latitude": 47.64056,
"longitude": -122.129372
},
{
"latitude": 47.64053,
"longitude": -122.129387
},

...

],
"summary": {
"arrivalTime": "2018-09-18T04:17:25Z",
"departureTime": "2018-09-18T03:54:35Z",
"lengthInMeters": 20742,
"trafficDelayInSeconds": 0,
"travelTimeInSeconds": 1370
}
}
]
"value": "geo:latitude,longitude"
}
```

This event can be customized to return whatever route data is required for your client's needs.

## Configuration

### Supported Sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,7 @@ public MainDialog(
var replyMessage = _responseManager.GetResponse(RouteResponses.SendingRouteDetails);
await dc.Context.SendActivityAsync(replyMessage);

// Send event with active route data
var replyEvent = dc.Context.Activity.CreateReply();
replyEvent.Type = ActivityTypes.Event;
replyEvent.Name = "ActiveRoute.Directions";
replyEvent.Value = state.ActiveRoute.Legs;
await dc.Context.SendActivityAsync(replyEvent);
await dc.Context.SendActivityAsync(PointOfInterestDialogBase.CreateOpenDefaultAppReply(dc.Context.Activity, state.Destination));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ public PointOfInterestDialogBase(

protected ResponseManager ResponseManager { get; set; }

public static Activity CreateOpenDefaultAppReply(Activity activity, PointOfInterestModel destination)
{
var replyEvent = activity.CreateReply();
replyEvent.Type = ActivityTypes.Event;
replyEvent.Name = "OpenDefaultApp";
replyEvent.Value = $"geo:{destination.Geolocation.Latitude},{destination.Geolocation.Longitude}";
return replyEvent;
}

protected override async Task<DialogTurnResult> OnBeginDialogAsync(DialogContext dc, object options, CancellationToken cancellationToken = default(CancellationToken))
{
return await base.OnBeginDialogAsync(dc, options, cancellationToken);
Expand Down Expand Up @@ -626,7 +635,7 @@ protected async Task<List<Card>> GetRouteDirectionsViewCards(DialogContext sc, R

if (routes != null)
{
state.FoundRoutes = routes.ToList();
state.FoundRoutes = routes.Select(route => route.Summary).ToList();

var destination = state.Destination;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,7 @@ public async Task<DialogTurnResult> ResponseToStartRoutePrompt(WaterfallStepCont
// workaround. if connect skill directly to teams, the following response does not work.
if (sc.Context.Adapter is IRemoteUserTokenProvider remoteInvocationAdapter || Channel.GetChannelId(sc.Context) != Channels.Msteams)
{
// Send event with active route data
var replyEvent = sc.Context.Activity.CreateReply();
replyEvent.Type = ActivityTypes.Event;
replyEvent.Name = "ActiveRoute.Directions";

var eventPayload = new DirectionsEventResponse
{
Destination = state.Destination,
Route = state.ActiveRoute
};
replyEvent.Value = eventPayload;

await sc.Context.SendActivityAsync(replyEvent);
await sc.Context.SendActivityAsync(CreateOpenDefaultAppReply(sc.Context.Activity, state.Destination));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public PointOfInterestSkillState()

public List<PointOfInterestModel> LastFoundPointOfInterests { get; set; }

public RouteDirections.Route ActiveRoute { get; set; }
public RouteDirections.Summary ActiveRoute { get; set; }

public List<RouteDirections.Route> FoundRoutes { get; set; }
public List<RouteDirections.Summary> FoundRoutes { get; set; }

public string DialogName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public sealed class AzureMapsGeoSpatialService : IGeoSpatialService
private static readonly string ImageUrlByPoint = $"https://atlas.microsoft.com/map/static/png?api-version=1.0&layer=basic&style=main&zoom={{2}}&center={{1}},{{0}}&width={ImageWidth}&height={ImageHeight}";
private static readonly string ImageUrlForRoute = $"https://atlas.microsoft.com/map/static/png?api-version=1.0&layer=basic&style=main&zoom={{0}}&center={{1}},{{2}}&width={ImageWidth}&height={ImageHeight}&pins={{3}}&path=lw2|lc0078d4|{{4}}";
private static readonly string RoutePins = "default|la15+50|al0.75|cod83b01||'{0}'{1} {2}|'{3}'{4} {5}";
private static readonly string GetRouteDirections = $"https://atlas.microsoft.com/route/directions/json?&api-version=1.0&instructionsType=text&query={{0}}";
private static readonly string GetRouteDirectionsWithRouteType = $"https://atlas.microsoft.com/route/directions/json?&api-version=1.0&instructionsType=text&query={{0}}&&routeType={{1}}";
private static readonly string GetRouteDirections = $"https://atlas.microsoft.com/route/directions/json?&api-version=1.0&instructionsType=text&query={{0}}&maxAlternatives=2";
private static readonly string GetRouteDirectionsWithRouteType = $"https://atlas.microsoft.com/route/directions/json?&api-version=1.0&instructionsType=text&query={{0}}&&routeType={{1}}&maxAlternatives=2";
private static string apiKey;
private static string userLocale;
private static HttpClient httpClient;
Expand Down

0 comments on commit 38faf40

Please sign in to comment.