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.3 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
66
67
68
  1. // This loads the environment variables from the .env file
  2. require('dotenv-extended').load();
  3. var builder = require('botbuilder');
  4. var restify = require('restify');
  5. // Setup Restify Server
  6. var server = restify.createServer();
  7. server.listen(process.env.port || process.env.PORT || 3978, function () {
  8. console.log('%s listening to %s', server.name, server.url);
  9. });
  10. // Create connector and listen for messages
  11. var connector = new builder.ChatConnector({
  12. appId: process.env.MICROSOFT_APP_ID,
  13. appPassword: process.env.MICROSOFT_APP_PASSWORD
  14. });
  15. server.post('/api/messages', connector.listen());
  16. var instructions = 'Welcome to the Bot to showcase the DirectLine API. Send \'Show me a hero card\' or \'Send me a BotFramework image\' to see how the DirectLine client supports custom channel data. Any other message will be echoed.';
  17. var bot = new builder.UniversalBot(connector, function (session) {
  18. var reply = new builder.Message()
  19. .address(session.message.address);
  20. var text = session.message.text.toLocaleLowerCase();
  21. switch (text) {
  22. case 'show me a hero card':
  23. reply.text('Sample message with a HeroCard attachment')
  24. .addAttachment(new builder.HeroCard(session)
  25. .title('Sample Hero Card')
  26. .text('Displayed in the DirectLine client'));
  27. break;
  28. case 'send me a botframework image':
  29. reply.text('Sample message with an Image attachment')
  30. .addAttachment({
  31. contentUrl: 'https://docs.microsoft.com/en-us/bot-framework/media/how-it-works/architecture-resize.png',
  32. contentType: 'image/png',
  33. name: 'BotFrameworkOverview.png'
  34. });
  35. break;
  36. default:
  37. reply.text('You said \'' + session.message.text + '\'');
  38. break;
  39. }
  40. session.send(reply);
  41. });
  42. bot.on('conversationUpdate', function (activity) {
  43. // when user joins conversation, send instructions
  44. if (activity.membersAdded) {
  45. activity.membersAdded.forEach(function (identity) {
  46. if (identity.id === activity.address.bot.id) {
  47. var reply = new builder.Message()
  48. .address(activity.address)
  49. .text(instructions);
  50. bot.send(reply);
  51. }
  52. });
  53. }
  54. });
Tip!

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

Comments

Loading...