Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.js 2.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  1. var util = require('util');
  2. var _ = require('lodash');
  3. var builder = require('botbuilder');
  4. var restify = require('restify');
  5. /// <reference path="../SearchDialogLibrary/index.d.ts" />
  6. var SearchLibrary = require('../SearchDialogLibrary');
  7. var AzureSearch = require('../SearchProviders/azure-search');
  8. // Setup Restify Server
  9. var server = restify.createServer();
  10. server.listen(process.env.port || process.env.PORT || 3978, function () {
  11. console.log('%s listening to %s', server.name, server.url);
  12. });
  13. // Create chat bot and listen for messages
  14. var connector = new builder.ChatConnector({
  15. appId: process.env.MICROSOFT_APP_ID,
  16. appPassword: process.env.MICROSOFT_APP_PASSWORD
  17. });
  18. server.post('/api/messages', connector.listen());
  19. // Bot with main dialog that triggers search and display its results
  20. var bot = new builder.UniversalBot(connector, [
  21. function (session) {
  22. // Trigger Search
  23. SearchLibrary.begin(session);
  24. },
  25. function (session, args) {
  26. // Process selected search results
  27. session.send(
  28. 'Done! For future reference, you selected these properties: %s',
  29. args.selection.map(function (i) { return i.key; }).join(', '));
  30. }
  31. ]);
  32. // Azure Search
  33. var azureSearchClient = AzureSearch.create('realestate', '82BCF03D2FC9AC7F4E9D7DE1DF3618A5', 'listings');
  34. var realStateResultsMapper = SearchLibrary.defaultResultsMapper(realstateToSearchHit);
  35. // Register Search Dialogs Library with bot
  36. bot.library(SearchLibrary.create({
  37. multipleSelection: true,
  38. search: function (query) { return azureSearchClient.search(query).then(realStateResultsMapper); },
  39. refiners: ['region', 'city', 'type'],
  40. refineFormatter: function (refiners) {
  41. return _.zipObject(
  42. refiners.map(function (r) { return 'By ' + _.capitalize(r); }),
  43. refiners);
  44. }
  45. }));
  46. // Maps the AzureSearch RealState Document into a SearchHit that the Search Library can use
  47. function realstateToSearchHit(realstate) {
  48. return {
  49. key: realstate.listingId,
  50. title: util.format('%d bedroom, %d bath in %s, $%s',
  51. realstate.beds, realstate.baths, realstate.city, realstate.price.toFixed(2)),
  52. description: realstate.description,
  53. imageUrl: realstate.thumbnail
  54. };
  55. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...