Guest User

Untitled

a guest
Dec 5th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. /* conversation.js */
  2.  
  3. const ConversationV1 = require('watson-developer-cloud/conversation/v1');
  4. // new instance of Conversation
  5. const conversation = new ConversationV1({
  6. username: process.env.CONVERSATION_USERNAME,
  7. password: process.env.CONVERSATION_PASSWORD,
  8. version_date: ConversationV1.VERSION_DATE_2017_02_03
  9. });
  10. /**
  11. * Call to Conversation API: send message
  12. *
  13. * @param {string} text
  14. * @param {object} context
  15. * @returns {promise}
  16. */
  17. exports.sendMessage = (text, context) => {
  18. const payload = {
  19. workspace_id: process.env.WORKSPACE_ID,
  20. input: {
  21. text: text
  22. },
  23. context: context
  24. };
  25. return new Promise((resolve, reject) => conversation.message(payload, function (err, data) {
  26. if (err) {
  27. reject(err);
  28. } else {
  29. resolve(data);
  30. }
  31. }));
  32. };
Add Comment
Please, Sign In to add comment