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.5 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
63
64
65
  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 the refine dialog with 'business_title' facet.
  23. // Then continue the dialog waterfall with the selected refiner/filter
  24. SearchLibrary.refine(session,
  25. {
  26. refiner: 'business_title',
  27. prompt: 'Hi! To get started, what kind of position are you looking for?'
  28. });
  29. },
  30. function (session, args) {
  31. // trigger Search dialog root, using the generated Query created by /refine
  32. var query = args.query;
  33. SearchLibrary.begin(session, { query: query });
  34. },
  35. function (session, args) {
  36. // Process selected search results
  37. session.send(
  38. 'Done! For future reference, you selected these job listings: %s',
  39. args.selection.map(function (i) { return i.key; }).join(', '));
  40. }
  41. ]);
  42. // Azure Search provider
  43. var azureSearchClient = AzureSearch.create('azs-playground', '512C4FBA9EED64A31A1052CFE3F7D3DB', 'nycjobs');
  44. var jobsResultsMapper = SearchLibrary.defaultResultsMapper(jobToSearchHit);
  45. // Register Search Dialogs Library with bot
  46. bot.library(SearchLibrary.create({
  47. multipleSelection: true,
  48. search: function (query) { return azureSearchClient.search(query).then(jobsResultsMapper); },
  49. refiners: ['business_title', 'agency', 'work_location']
  50. }));
  51. // Maps the AzureSearch Job Document into a SearchHit that the Search Library can use
  52. function jobToSearchHit(job) {
  53. return {
  54. key: job.id,
  55. title: util.format('%s at %s, %s to %s', job.business_title, job.agency, job.salary_range_from.toFixed(2), job.salary_range_to.toFixed(2)),
  56. description: job.job_description.substring(0, 512) + '...'
  57. };
  58. }
Tip!

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

Comments

Loading...