Code Monkey home page Code Monkey logo

botkit-middleware's People

Contributors

aarora91 avatar ambercraig avatar dependabot[bot] avatar dgterry avatar germanattanasio avatar greenkeeper[bot] avatar mamoonraja avatar naktibalda avatar pmundt avatar riyamroy04 avatar rob-pocklington-a139759 avatar stevenoh93 avatar toxuin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

botkit-middleware's Issues

Need full working example of middleware with Spark, implementing app actions + returning updated context to Watson

I've tried to carefully follow the provided instructions to create Watson middleware for a Spark Bot, but aside from the trivial example (in which the bot simply relays what Watson says), I can't get it to work. The problem is that the instructions don't make it clear how to combine code from different sections of the Readme file (e.g. basic setup + message filtering + implementing app actions while updating context and sending these updates asynchronously to Watson), and I tried different combinations with no success (either the 'implementing app actions' part doesn't run at all, or the basic interaction is completely broken, etc).
It would be extremely helpful if you could provide a full working example that does all these things. Thanks!

Send another message to Conversation containing result of action

Hi,

I've read https://www.ibm.com/watson/developercloud/doc/conversation/develop-app.html#implementing-app-actions and implemented prototype with PHP.

My Coversation chatbot delegates some validation actions to client code:

{
  "context": {
    "cardNumber": "<? input.text.extract('[\\d]{8}',0) ?>"
  },
  "output": {
    "text": {
      "values": [
        "Perfect, I'll just look up the details for you"
      ],
      "selection_policy": "sequential"
    },
    "action": "validate_card_number"
  }
}

Client code performs validation, sets a few context variables and sends empty message to Conversation to execute the next step of dialog.

Pseudo code:

response = sendMessage(message)
if output.action == 'validate_card_number'
  context.isValidCard = validateCardNumber(context.cardNumber)
  newResponse = sendMessage('', context)

How could I implement this functionality using botkit and watson middleware?

ERROR: message.watsonError is seen

Hello,

I tried to connect Facebook Bot to Watson conversation.
So I referenced below site.
https://www.youtube.com/watch?v=FdsjS7ZnPLw

But In my case, Watson message error is seen. Below is my source code.

controller.hears('(.*)','message_received', function (bot, message) {
console.log("message.watsonError" + message.watsonError);
if (message.watsonError) {
bot.reply(message, "I'm sorry, but for technical reasons I can't respond to your message");
} else {
bot.reply(message, message.watsonData.output.text.join('\n'));
}
});

In my console, If I print "message.watsonError" variable, the result is "message.watsonErrorError: Forbidden".

It would be helpful, if you give me some idea.
Thanks you.

message.watsonData is undefined

I'm using a basic example just like in the README.

property watsonData does not exist on message (msg).

sreenshot- 2017-05-04 at 12 39 28 pm

It seems an odd choice to mutate the incoming message instead of providing a separate object as a response. But anyway, it seems not to be working.

Relevant chunks of code:

controller.middleware.receive.use(watsonConv.receive);
log('using middleware watson');

controller.hears(['.*'], ['direct_message', 'direct_mention', 'mention'],  function(bot, msg) {
  log('watson hears', msg.text);
  bot.reply(msg, msg.watsonData.output.text.join('\n'));
});
Fatal TypeError: Cannot read property 'output' of undefined
    at /work/watson/mms-slack/src/index.js:96:32
    at /work/watson/mms-slack/node_modules/botkit/lib/CoreBot.js:1019:32
    at next (/work/watson/mms-slack/node_modules/ware/lib/index.js:82:27)
    at Ware.run (/work/watson/mms-slack/node_modules/ware/lib/index.js:88:3)
    at Object.<anonymous> (/work/watson/mms-slack/node_modules/botkit/lib/CoreBot.js:1018:49)
    at Object.Botkit.botkit.trigger (/work/watson/mms-slack/node_modules/botkit/lib/CoreBot.js:1047:49)
    at Object.<anonymous> (/work/watson/mms-slack/node_modules/botkit/lib/SlackBot.js:738:34)
    at Object.Botkit.botkit.trigger (/work/watson/mms-slack/node_modules/botkit/lib/CoreBot.js:1047:49)
    at /work/watson/mms-slack/node_modules/botkit/lib/CoreBot.js:1155:32
    at Object.bot.findConversation (/work/watson/mms-slack/node_modules/botkit/lib/Slackbot_worker.js:752:9)
    at /work/watson/mms-slack/node_modules/botkit/lib/CoreBot.js:1151:21
    at next (/work/watson/mms-slack/node_modules/ware/lib/index.js:82:27)
    at /work/watson/mms-slack/node_modules/wrap-fn/index.js:121:18
    at /work/watson/mms-slack/node_modules/botkit-middleware-watson/lib/middleware/index.js:154:9
    at tryCatcher (/work/watson/mms-slack/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/work/watson/mms-slack/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/promise.js:512:31)

Process finished with exit code 2

Localtunnel issue

i'm having an issue with localtunnel and botkit. I setup all the correct fields in the .env file (USE_FACEBOOK=true, watsonID, PSW, etc...).
I open the cmd and type

'lt --s watsontyres --p 5000'

where watsontyres is my appname, the reply is

'your url is: https://watsontyres.localtunnel.me'.

I type 'node server.js' and:

info: ** No persistent storage method specified! Data may be lost when process shuts down.
info: ** Serving webhook endpoints for Messenger Platform at: http://MY_HOST:undefined/facebook/receive
Facebook bot is live
Client server listening on port 5000

So i think the problem is here, because it doesn't show the correct url.
Next i go on facebook dev page and when i try to setup the webhook it says 502 bad gateway.
Can you help me solving this problem please?

Export readContext method

I came up with scenario where I need to call readContext from the bot code.

It is in controller.on('event', (bot, message) => {})
Which is used to process events sent by the client.

Since they have no text, events aren't passed through middleware, so they have no watsonData property. If I want to updateContext after processing a particular event, I have to read it first.

controller.on('event', (bot, message) => {
  //readContext
  //processing
  //updateContext
  //sendToWatson
}

How to send the empty message to Watson when a new session is created

All bot examples in Developer Cloud start with

// Start conversation with empty message.
conversation.message({}, processResponse);

It triggers conversation_start event in Conversation.

However this code in middleware makes middleware ignore empty messages.

Is there a workaround?

Actually there is a bug in that code - it doesn't call return after callback, so execution continues and the message is sent to Watson Conversation anyway, but the answer is ignored.

Watson Conversation is called with the response payload

I got up and running with botkit and the watson middleware.

When I looked at the logs in the "improve" tab, I noticed that Watson Conversation was also getting called with the response payload.

In my example I would issue a "hello", Watson would respond with a "Hello Again" but then the code was sending this response back to the server as a user request so I would also see in the improve logs an utterance coming from the user of "Hello Again".

I debugged the code and it looks like receive also gets called when a message is sent back to the client (this was slack). I hacked the code below to look for bot_id and this seems to have fixed it, but it may well only work for slack.

      if (!middleware.conversation) {
        debug('Creating Conversation object with parameters: ' + JSON.stringify(config, 2, null));
        middleware.conversation = new ConversationV1(config);
      }

      if (!message.text || ignoreType.indexOf(message.type) !== -1 || message.reply_to || message.bot_id) {
        // Ignore messages initiated by Slack. Reply with dummy output object

        message.watsonData = {
          output: {
            text: []
          }
        };
        return message;
      }

Using Conversation in new Frankfurt region

trying to use a Conversation service, instantiated in the new Bluemix Frankfurt region, I received following message:

Fatal TypeError: Cannot read property 'output' of undefined

It seems that new region not yet supported by WDC SDK.
Workaround:

  • add new parameter in .env file
    CONVERSATION_URL=https://gateway-fra.watsonplatform.net/conversation/api

  • take this parameter in account in app.js

var middleware = require('botkit-middleware-watson')({
  username: process.env.CONVERSATION_USERNAME,
  password: process.env.CONVERSATION_PASSWORD,
  workspace_id: process.env.WORKSPACE_ID,
  url: process.env.CONVERSATION_URL || 'https://gateway.watsonplatform.net/conversation/api' , 
  version_date: '2016-09-20'
});

Is it the best way ? another suggestion ?

Integration with twilio SMS

Hi,
How can we make chat bot working with Twilio SMS.
Let say I am sending SMS to Twilio number and it is replying back with response.

Is this Possible to integrate that flow here.

Any sample example will be useful to start with.

Thanks,
Vishwas

Text formatting for slack

Is there a way to do formatting when I reply the message to slack? I just want to output a JSON array as a list. I tried things as simple as newline (\n, \n\n). But it doesn't seem to reflect on the slack side....

Thank you very much for your help.

Cannot read property 'output' of undefined

I am trying the sample code for building a Slackbot using the simple-bot in the examples folder. I am trying a toy example with a single intent and a simple dialog.

I updated the relevant keys in the .env file and ran npm start. When I type in a message on Slack I get a Fatal TypeError: Cannot read property 'output' of undefined error on simple-bot/simple-bot-slack.js:39:42 on the server. And the bot shuts down.

I tried running the code in debug mode and I can see the watson-middleware:utils Conversation Response object with the correct intent, output (from Conversation) etc but still the error.

Watson - Developer

Hi,
I wonder if Watson can work only with JavaScript to develop within the Conversation code that will store data in a variable and run a script.

Thanks.

Send two responses for one request from facebook

Hi,
I am using this middleware to integrate watson conversation and facebook messanger.
I have specific requirement that.
When user is asking near by location then need send:

  1. First response will be " Let me find these locations for you"
  2. Second response will be after few seconds (1-2), with actual results from external api call.

Is there any way to handle this?

Thanks,
Vishwas

Intercepting Conversation answer to query database - lost of context ?

Following issue #24...

Scenario:
intercept answer from Watson Conversation (event middleware.after), query a DB and answer directly to Conversation without using Messenger. Conversation will then interpret/format and answer to the user, using data retrieved from DB.

So my program does:

  • receive conversationResponse in event middleware.after
  • query DB, and get answer
  • update Conversation Payload with DB result
  • answer to Conversation / receive Conversation answer
  • call callback to answer to user (Messenger)

In Conversation simulator, it works fine, but not in this program.
It seems that the call of middleware.conversation.message (after DB call) increments dialog_turn_counter (and it's OK) but the callback reset dialog_turn_counter to the value before the call of middleware.conversation.message.

See code & trace in PDF.

Issue_BotKit.pdf

replyWithTyping function

Hi,

I'm using this middleware to connect watson conversation with fb messenger, but when i try to use replyWithTyping i get the error:
bot.replyWithTyping is not a function and with
bot.reply everything works fine

Could you help me with this? thanks

Watson Middleware "hear" does not support regex

I was trying to understand why the following code wasn't working

slackController.changeEars(watsonMiddleware.hear);
slackController.hears(['.*'], ['direct_message', 'direct_mention', 'mention'], function(bot, message) {
    var reply = {

In debugging it, it appears that the middleware hears function doesn't support regex and I think it needs to so greater control over the selected intents can be done.

The change is fairly simple and I include it below. The code is taken from botkit's matching algorithm

hear: function(tests, message) {
      for (var t = 0; t < tests.length; t++) {
          if (message.watsonData && message.watsonData.intents) {
              // the pattern might be a string to match (including regular expression syntax)
              // or it might be a prebuilt regular expression
              var test = null;
              if (typeof(tests[t]) == 'string') {
                  try {
                      test = new RegExp(tests[t], 'i');
                  } catch (err) {
                      botkit.log('Error in regular expression: ' + tests[t] + ': ' + err);
                      return false;
                  }
                  if (!test) {
                      return false;
                  }
              } else {
                  test = tests[t];
              }

              for (var i = 0; i < message.watsonData.intents.length; i++) {
                if (match = message.watsonData.intents[i].intent.match(test) &&
                  message.watsonData.intents[i].confidence >= middleware.minimum_confidence) {
                    message.match = match;
                  return true;
                }
              }
            }
          }
      return false;
    },

Using temporary storage

I'm using simple-bot and my bot keeps restarting conversation rather continuing on the same one (Creating new session everytime a message is sent). Additionally, it would reply with a dialog with given intents (such as #intent) and would ignore welcome and anything_else dialogs.

Tried run as administrator.

info: ** No persistent storage method specified! Data may be lost when process shuts down.
info: ** Setting up custom handlers for processing Slack messages
info: ** API CALL: https://slack.com/api/rtm.start
Client server listening on port 5000
notice: ** BOT ID: test ...attempting to connect to RTM!
notice: RTM websocket opened
info: Slack message received
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Slack message received
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Slack message received
info: Slack message received
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Slack message received
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Slack message received
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Slack message received
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Slack message received
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Slack message received
info: Warning: using temporary storage. Data will be lost when process restarts.

[Docs] What's the point of interpret() function?

I read README down to the bottom for the first (or maybe second) time now.

Documentation says that interpret is somehow different from receive when it clearly is just a copy.
https://github.com/watson-developer-cloud/botkit-middleware/tree/master#interpret
The whole section looks misleading to me. "mapping" and "triggering" is a choice of developer who integrates watson middleware to botkit. Interpret can be used as middleware, and receive can be called from controller.

I think that instead of documenting functions, it would be better to have a feature section like "Call Conversation for selected messages only", which should advice to not to register middleware and call function from controller.

Account Linking Support?

Hi,

I want to know if this botkit support https://developers.facebook.com/docs/messenger-platform/account-linking/link-account

And how can merge with watson conversation, for example I do this on bot-facebook.js

 var attachment = {
        'type':'template',
        'payload':{
            'template_type':'generic',
            'elements':[
                {
                    'title':'Welcome to Account Linking',
                    'image_url':'https://xxx/linking.png',
                    'buttons':[                       
                        {
                        'type':'account_link',
                        'url':'xxx/login.html'
                        }
                    ]
                },
            ]
        }

And on server.js

app.get('/authorize', function (req, res, next) {
 // {...}
}

The linking works, but I'm not able to send to conversation a context variable with a custom var filling with "success" or a token..

Its possible ussing account_linking ?

ERROR: message.watsonError is seen

Hello,

I tried to connect Facebook Bot to Watson conversation.
So I referenced below site.
https://www.youtube.com/watch?v=FdsjS7ZnPLw

But In my case, Watson message error is seen. Below is my source code.

controller.hears('(.*)','message_received', function (bot, message) {
  console.log("message.watsonError" + message.watsonError);
  if (message.watsonError) {
    bot.reply(message, "I'm sorry, but for technical reasons I can't respond to your message");
  } else {
    bot.reply(message, message.watsonData.output.text.join('\n'));
  }
});

Although I can see text message in facebook messenger like "I'm sorry, but for technical reasons, I can't respond to your message", I can't see Watson Data.
In my console, If I print "message.watsonError" variable, the result is "message.watsonErrorError: Forbidden".
For Reference, I already applied watson CONVERSATION_USERNAME, CONVERSATION_PASSWORD, WORKSPACE_ID, CONVERSATION_URL to .env file.

It would be helpful if you give me some idea.
Thank you.

Webhook - Facebook returns 404

The local tunnel is running fine. I'm starting using the conversation simple repository.

It already has an app.js file. Do I need to add the content from here to the end of my file?

I got this message on facebook messenger integration. The URL couldn't be validated. Callback verification failed with the following errors: HTTP Status Code = 404; HTTP Message = Not Found

When I go to this URL https://rsikyaeerl.localtunnel.me/facebook/receive I got: Cannot GET /facebook/receive

What's wrong?

readme file typo in sample code - needs correction

Thanks for sharing this useful middleware!. Just getting started with it, and I noticed that your section entitled 'Using updateContext in controller (available since v1.4.0)' has a function called 'checkBalance' that is using an undefined 'watsonResponse' variable (apparently defined in the previous example, since it was one of the original parameters of that function). Hope you can correct it when you have a chance. Thanks!

With Cisco Spark

Hi, I'm Kotaro. I wanna use this plugin with Cisco Spark but It seems "unsupported" yet. If possible, please give me a solution. I wanna know how I can use. Which part should I change??

Error install botKit

Hello guys, I'm trying to install botkit, but it always gives a bug, could anyone help me?

npm install botkit-middleware-watson --save

  npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config - -get remote.origin.url 
  npm WARN addRemoteGit 
  npm WARN addRemoteGit at ChildProcess.exithandler (child_process.js:211:12) 
  npm WARN addRemoteGit at emitTwo (events.js:106:13) 
  npm WARN addRemoteGit at ChildProcess.emit (events.js:192:7) 
  npm WARN addRemoteGit at maybeClose (internal/child_process.js:890:16) 
  npm WARN addRemoteGit at Socket. (internal/child_process.js:334:1 1) 
  npm WARN addRemoteGit at emitOne (events.js:96:13) 
  npm WARN addRemoteGit at Socket.emit (events.js:189:7) 
  npm WARN addRemoteGit at Pipe._handle.close [as _onclose] (net.js:501:12) 
  npm WARN addRemoteGit git://github.com/ianwremmel/extend-error.git resetting re mote C:\Users\rcborges\AppData\Roaming\npm-cache_git-remotes\git-github-com-ian wremmel-extend-error-git-024938ae because of error: { Error: Command failed: git -c core.longpaths=true config --get remote.origin.url 
  npm WARN addRemoteGit 
  npm WARN addRemoteGit at ChildProcess.exithandler (child_process.js:211:12) 
  npm WARN addRemoteGit at emitTwo (events.js:106:13) 
  npm WARN addRemoteGit at ChildProcess.emit (events.js:192:7) 
  npm WARN addRemoteGit at maybeClose (internal/child_process.js:890:16) 
  npm WARN addRemoteGit at Socket. (internal/child_process.js:334:1 1) 
  npm WARN addRemoteGit at emitOne (events.js:96:13) 
  npm WARN addRemoteGit at Socket.emit (events.js:189:7) 
  npm WARN addRemoteGit at Pipe._handle.close [as _onclose] (net.js:501:12) 
  npm WARN addRemoteGit killed: false, 
  npm WARN addRemoteGit code: 1, 
  npm WARN addRemoteGit signal: null, 
  npm WARN addRemoteGit cmd: 'git -c core.longpaths=true config --get remote.ori gin.url' } 
  npm ERR! git clone --template=C:\Users\rcborges\AppData\Roaming\npm-cache_git-r emotes_templates --mirror git://github.com/ianwremmel/extend-error.git C:\Users \rcborges\AppData\Roaming\npm-cache_git-remotes\git-github-com-ianwremmel-exten d-error-git-024938ae: Cloning into bare repository 'C:\Users\rcborges\AppData\Ro aming\npm-cache_git-remotes\git-github-com-ianwremmel-extend-error-git-024938ae '... 
  npm ERR! git clone --template=C:\Users\rcborges\AppData\Roaming\npm-cache_git-r emotes_templates --mirror git://github.com/ianwremmel/extend-error.git C:\Users \rcborges\AppData\Roaming\npm-cache_git-remotes\git-github-com-ianwremmel-exten d-error-git-024938ae: fatal: unable to connect to github.com: 
  npm ERR! git clone --template=C:\Users\rcborges\AppData\Roaming\npm-cache_git-r emotes_templates --mirror git://github.com/ianwremmel/extend-error.git C:\Users \rcborges\AppData\Roaming\npm-cache_git-remotes\git-github-com-ianwremmel-exten d-error-git-024938ae: github.com[0: 192.30.253.113]: errno=No error 
  npm ERR! git clone --template=C:\Users\rcborges\AppData\Roaming\npm-cache_git-r emotes_templates --mirror git://github.com/ianwremmel/extend-error.git C:\Users \rcborges\AppData\Roaming\npm-cache_git-remotes\git-github-com-ianwremmel-exten d-error-git-024938ae: github.com[1: 192.30.253.112]: errno=No error 
  npm ERR! Windows_NT 6.1.7601 
  npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Users\rcborges\AppDat a\Roaming\npm\node_modules\npm\bin\npm-cli.js" "install" 
  npm ERR! node v7.5.0 
  npm ERR! npm v4.3.0 
  npm ERR! code 128


npm ERR! Command failed: git -c core.longpaths=true clone --template=C:\Users\rc borges\AppData\Roaming\npm-cache_git-remotes_templates --mirror git://github.c om/ianwremmel/extend-error.git C:\Users\rcborges\AppData\Roaming\npm-cache_git- remotes\git-github-com-ianwremmel-extend-error-git-024938ae 
npm ERR! Cloning into bare repository 'C:\Users\rcborges\AppData\Roaming\npm-cac he_git-remotes\git-github-com-ianwremmel-extend-error-git-024938ae'... 
npm ERR! fatal: unable to connect to github.com: 
npm ERR! github.com[0: 192.30.253.113]: errno=No error 
npm ERR! github.com[1: 192.30.253.112]: errno=No error 
npm ERR! 
npm ERR! 
npm ERR! 
npm ERR! If you need help, you may report this error at: 
npm ERR! https://github.com/npm/npm/issues


npm ERR! Please include the following file with any support request: 
npm ERR! C:\Users\rcborges\AppData\Roaming\npm-cache_logs\2017-03-08T15_08_ 13_729Z-debug.log 

Poor error handling in receive function

https://github.com/watson-developer-cloud/botkit-middleware/blob/v1.3.1/lib/middleware/index.js#L151-L152

.catch(function(error) {
  debug('Error: %s', JSON.stringify(error, Object.getOwnPropertyNames(error), 2));
})

This is a terrible way to handle errors.
By default it doesn't print anything in console and nobody enables debug messages in production.

If error happened in readContext, before, postMessage or after, it is possible to detect it by checking if message.watsonData is missing, but if error happened in updateContext, there is no way to detect it from the bot code.

Update README

Example GIF for chatting with a Slack bot connected to Watson Conversation:
ezgif com-gif-maker 1

[Feature request] Export updateContext function

In my project, when Conversation returns output.action = 'something', I want to store the result of action in context storage.

Currently the only way to access updateContext function is by using

var watsonUtils = require('./node_modules/botkit-middleware-watson/lib/middleware/utils.js');
watsonUtils.updateContext(
    message.user,
    watsonMiddleware.storage,
    {
        context: context
    },
    callback
);

I have been told that the code would become even uglier if I wanted to use it in a library.

It would be much more convenient to use it if I could call watsonMiddleware.updateContext.

phrase "I do not understand." from unknown source

in Watson Conversation, I get the response โ€œI do not understand.โ€ I have scoured the stack, and do not see this phrase anywhere:

  • my app
  • node_modules
  • botkit
  • botkit-middleware-watson
  • my Dialog config JSON

I already have an anything_else node, with different phrases.
Sometimes the phrase comes up, and then the bot moves to the next step.

In fact, a series of nonsense questions in the "Test it Out" feature at https://www.ibmwatsonconversation.com I get the expected response.

Can someone identify the source or how to debug/find it?

sreenshot- 2017-05-18 at 11 20 09 am
sreenshot- 2017-05-18 at 11 17 03 am

Example debug output:

Hears:	eeeeeep opppp Orkk AH-HA!
189b7a08-2d24-4ddc-9327-75d8eb38a930
exited:	true
stack:	1
turn:	336
info: >   [End]  0  Conversation with  W3NKCD3GX in D5844SSKA
info: [End]  0  Task for  W3NKCD3GX in D5844SSKA

How do I implement before: and after: methods in a SLACK bot

New to Node.js and not sure how to make use of these methods in a simple SLACK bot.... I want to call an external service to fetch data based on context variables from the conversation. THe variables are there now, I can see them coming across.
Questions:

  1. How do I make use of these methods?!
  2. Are these methods asynchronous?
  3. How do I get Watson conversation context into these methods so I can pull the parameters passed in?

A small example would be much appreciated, plz.

slackController.hears(['.*'], ['direct_message', 'direct_mention', 'mention'], function(bot, message) {
	  slackController.log('Slack message received');
	  //middleware.before(bot, message, function(beferr) {
		    //	  console.log('Inside the before method.  messageB=' + JSON.stringify(message, 2, null));
			//});
	  middleware.interpret(bot, message, function(err) {
	    if (!err)
			  bot.reply(message, message.watsonData.output.text.join('\n'));
	          console.log('**********>message.watsonData.context=' + JSON.stringify(message.watsonData.context, 2, null));
	          //console.log('message.watsonData.output=' + message.watsonData.output.text.join('\n'));
		});
	 // middleware.after(bot, message, function(afterr) {
		 //   	console.log('Inside the after method.  messageA=' + JSON.stringify(message, 2, null));
		

Handle user location

I'm trying to handle a location sent by user with FB Messenger (something like pull request #16)

I'm able to intercept and change message in middleware.before (add input.text, update Conversation variable lat/long). In Watson Conversation, message is well received, and an answer is generated and sent back to FB Messenger user.
But...
FB Messenger user never receive this message.
Any idea ?

Code and trace in attached file below

Issue_BotKit_2.pdf

Intercepting Conversation answer to query database

I'm trying to develop a bot using botkit-middleware-watson for FB messenger.
Dialog Conversation <-> Messenger runs good.

But now I want to intercept answer from Watson Conversation (event middleware.after ?), query a DB and answer directly to Conversation without using Messenger. Conversation will then interpret/format and answer to the user, using data retrieved from DB.

So my program have to (in event middleware.after ?)

  • receive conversationResponse
  • query DB, and get answer (son)
  • update Conversation Payload
  • answer to Conversation

Do you have any idea ?

npm install failed

Hi, npm install failed with the following message, any advice would be appreciated:

C:\Training\WEX\botkit-middleware-master\botkit-middleware-master>npm install botkit-middleware-watson --save
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "botkit-middleware-watson" under a package
npm ERR! also called "botkit-middleware-watson". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR!     <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Joe Yang\AppData\Roaming\npm-cache\_logs\2017-04-08T14_25_58_263Z-debug.log

Fatal TypeError: Cannot read property 'output' of undefined

I tried to use the simple-bot (locally) to connect my Watson Conversation service with my Slack channel. I exactly followed the instructions shown in the demo: https://www.youtube.com/watch?v=0rnt54ONtQw_. However I receive an error that the property 'output' could not be read. I double checked that my username and password is correct as indicated in another issue. When I change it to wrong values, the detailed debug output is different.
I then tried to log the message.watsonData object to the console before the bot.reply() method in line 37. This object was undefined as well.

StackTrace (before I made any changes to the code to log more to the console):

Fatal TypeError: Cannot read property 'output' of undefined
    at /Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/simple-bot-slack.js:37:42
    at /Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/botkit-middleware-watson/lib/middleware/index.js:106:9
    at tryCatcher (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:510:31)
    at Promise._settlePromise (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:691:18)
    at Promise._fulfill (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:636:18)
    at Promise._resolveCallback (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:431:57)
    at Promise._settlePromiseFromHandler (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:522:17)
    at Promise._settlePromise (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/promise.js:687:18)
    at Async._drainQueue (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/Users/chk/dev/playground/watsonConversation/botkit-middleware/examples/simple-bot/node_modules/bluebird/js/release/async.js:17:14)

Attached is the detailed debug log with NODE_DEBUG=request. I replaced credentials with *:
SlackWatsonConversationBox_trace.txt

Experiencing issue when integrating with Facebook

Hi I tried to integrate my watson conversation workspace with the botkit-middleware using Facebook as Messenger channel. The application crashes with the following error logs; whenever, I ask query for watson conversation.

API/2
App instance exited with guid 9e880f86-6d7c-4df6-a9bf-eed53ab35d71 payload: {"cc_partition"=>"default", "droplet"=>"9e880f86-6d7c-4df6-a9bf-eed53ab35d71", "version"=>"805409bf-3a43-4f18-bf60-8b93dd732ea0", "instance"=>"9e30a7d9fb6c48058d4a0a37410d9d6d", "index"=>0, "reason"=>"CRASHED", "exit_status"=>1, "exit_description"=>"app instance exited", "crash_timestamp"=>1479201318}
2016-11-15T13:15:18.717+0400
App/0
npm ERR! npm bugs fs-CognitApp
2016-11-15T13:15:18.554+0400
App/0
npm ERR! /home/vcap/app/npm-debug.log
2016-11-15T13:15:18.562+0400
App/0
npm ERR! Please include the following file with any support request:
2016-11-15T13:15:18.562+0400
App/0
npm ERR! npm owner ls fs-CognitApp
2016-11-15T13:15:18.555+0400
App/0
npm ERR! There is likely additional logging output above.
2016-11-15T13:15:18.555+0400
App/0
npm ERR!
2016-11-15T13:15:18.555+0400
App/0
npm ERR! Or if that isn't available, you can get their info via:
2016-11-15T13:15:18.555+0400
App/0
npm ERR! This is most likely a problem with the fs-CognitApp package,
2016-11-15T13:15:18.554+0400
App/0
npm ERR! Tell the author that this fails on your system:
2016-11-15T13:15:18.554+0400
App/0
npm ERR! You can get information on how to open an issue for this project with:
2016-11-15T13:15:18.554+0400
App/0
npm ERR! not with npm itself.
2016-11-15T13:15:18.554+0400
App/0
npm ERR! node server.js
2016-11-15T13:15:18.554+0400
App/0
npm ERR! Failed at the [email protected] start script 'node server.js'.
2016-11-15T13:15:18.554+0400
App/0
npm ERR! Exit status 2
2016-11-15T13:15:18.553+0400
App/0
npm ERR!
2016-11-15T13:15:18.553+0400
App/0
npm ERR! [email protected] start: `node server.js`
2016-11-15T13:15:18.553+0400
App/0
npm ERR! code ELIFECYCLE
2016-11-15T13:15:18.553+0400
App/0
npm ERR! npm v2.15.9
2016-11-15T13:15:18.553+0400
App/0
npm ERR! argv "/home/vcap/app/vendor/node/bin/node" "/home/vcap/app/vendor/node/bin/npm" "start"
2016-11-15T13:15:18.552+0400
App/0
at Promise._resolveCallback (/home/vcap/app/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/promise.js:431:57)
2016-11-15T13:15:18.513+0400
App/0
at Promise._settlePromise0 (/home/vcap/app/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/promise.js:612:10)
2016-11-15T13:15:18.513+0400
App/0
at Promise._settlePromise (/home/vcap/app/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/promise.js:567:18)
2016-11-15T13:15:18.513+0400
App/0
at tryCatcher (/home/vcap/app/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/util.js:16:23)
2016-11-15T13:15:18.513+0400
App/0
at Promise._fulfill (/home/vcap/app/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/promise.js:636:18)
2016-11-15T13:15:18.513+0400
App/0
at Promise._settlePromiseFromHandler (/home/vcap/app/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/promise.js:510:31)
2016-11-15T13:15:18.513+0400
App/0
at Object.bot.findConversation (/home/vcap/app/node_modules/botkit/lib/Facebook.js:103:13)
2016-11-15T13:15:18.513+0400
App/0
at /home/vcap/app/node_modules/botkit/lib/CoreBot.js:862:21
2016-11-15T13:15:18.513+0400
App/0
at /home/vcap/app/node_modules/botkit/node_modules/ware/node_modules/wrap-fn/index.js:121:18
2016-11-15T13:15:18.513+0400
App/0
at Promise._settlePromises (/home/vcap/app/node_modules/botkit-middleware-watson/node_modules/bluebird/js/release/promise.js:691:18)
2016-11-15T13:15:18.513+0400
App/0
Fatal TypeError: Cannot read property 'output' of undefined
2016-11-15T13:15:18.513+0400
App/0
at Object.Botkit.botkit.trigger (/home/vcap/app/node_modules/botkit/lib/CoreBot.js:779:49)
2016-11-15T13:15:18.513+0400
App/0
at next (/home/vcap/app/node_modules/botkit/node_modules/ware/lib/index.js:82:27)
2016-11-15T13:15:18.513+0400
App/0
at /home/vcap/app/node_modules/botkit-middleware-watson/lib/middleware/index.js:107:9
2016-11-15T13:15:18.513+0400
App/0
at /home/vcap/app/node_modules/botkit/lib/CoreBot.js:866:32
2016-11-15T13:15:18.513+0400
App/0
at Object.<anonymous> (/home/vcap/app/bot-facebook.js:26:40)
2016-11-15T13:15:18.513+0400
App/0
at Object.<anonymous> (/home/vcap/app/node_modules/botkit/lib/CoreBot.js:753:28)
2016-11-15T13:15:18.513+0400
RTR/1
fs-cognitapp.mybluemix.net - [15/11/2016:09:15:18.311 +0000] "POST /facebook/receive HTTP/1.1" 200 289 2 "-" "-" 192.155.237.115:15111 x_forwarded_for:"66.220.158.100" x_forwarded_proto:"https" vcap_request_id:de47848d-4dcd-4dc8-6242-c56ad13e32ec response_time:0.090544254 app_id:9e880f86-6d7c-4df6-a9bf-eed53ab35d71 x_global_transaction_id:"3446389437"
2016-11-15T13:15:18.402+0400
App/0
Client server listening on port 62408

Watson Conversation loses state, resets to root node rather than waiting for user input.

Hello,

I downloaded and updated the .env file with both my Watson Conversation Service (WCS) creds and my Slack API.

When I started the simple-bot example it seems to start fine. It receives input from Slack, and it queries WCS and posts a response back to Slack.

However, I am seeing an issue in one scenario.
I have a node that asks user for some clarification, the node is set to wait for user response and then continue.
When I try this on the WCS dialog chat, it works as expected. Context is kept, and the system picks up form the user input and continues on.
But when I try this from Slack, the user input doesn't seem to start from the node where it is expecting user input, but from the root node.

Another thing I am noticing which might be related to this issue is that the middleware seems to be pinging WCS. (See console log below)

`>npm start

[email protected] start /Users/robertloredo/Documents/projects/botkit-demo/examples/simple-bot
node simple-bot-slack.js

info: ** No persistent storage method specified! Data may be lost when process shuts down.
info: ** Setting up custom handlers for processing Slack messages
info: ** API CALL: https://slack.com/api/rtm.start
Client server listening on port 6002
notice: ** BOT ID: cqs-bot ...attempting to connect to RTM!
notice: RTM websocket opened
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Warning: using temporary storage. Data will be lost when process restarts.
info: Slack message received!
I `

As you can see this is repeating as when I post a slack message it works fine, but after the process is completed, it goes back to looping this message.

I'm wondering if this is also pinging WCS, if so, then this might be why it is resetting back to root node?

Any help is appreciated.

Thank you!

Robert

Handle overwrite output response

hi, i am trying to figure out how to overwrite the output in
middleware.after = function(message, conversationResponse, callback)

i tried to modify the last line to

conversationResponse.output.text = 'This is my custom output line';

however I'm guessing its read only as this causes it to crash. in previous lines i use conversationResponse.output.text to obtain what the bot will say so i know its valid. it just won't let me overwrite it.

we plan on using a database to get custom responses. however I'm stuck trying to figure out how to overwrite the default output.

any help is appreciated.

thanks
Dion

Waston output text is empty

{ type: 'message',
  channel: 'C6ESXUD2T',
  user: 'U6F4JLZ2T',
  text: 'hello',
  ts: '1501606591.751190',
  source_team: 'T6ESXU955',
  team: 'T6ESXU955',
  watsonData: { intents: [],
     entities: [],
     input: { text: 'hello' },
     output:
      { text: [],
        nodes_visited: [],
        warning: 'No dialog node matched for the input at a root level. (and there is 1 more warning in the log)',
        log_messages: [Array] },
     context:
      { conversation_id: '72af1b06-ec67-43e2-b5bf-73fa0e570ae6',
        system: [Object] } },
  event: 'ambient',
  match: [ 'hello', index: 0, input: 'hello' ] }`

do I have to do anything in watson dashboard?

Fb Bot ever response the same text

Hi,
I tryed multibot example, locally, in my own host (all of them with localtunne) and the last test was in bluemix, here: https://botfbw3.mybluemix.net/

All of them doenst works as expected,
imagen

Basically, in IBM tool online works well, but in FB Messenger dont, I'm the owner of the apps, so I can talk whit my fanpage...but the bot always anwers the same and the same, sound like a "cached" response.

I dont know if its a FB issue, or its a Watson conversation issue,

Could you please help us?

Thanks in advance

Conversation ends abruptly....

I'm using these in my sample work:
"botkit": "^0.5.8",
"botkit-middleware-watson": "^1.4.0"

My conversation is very simple, it asks three questions of the user to collect enough data to run a query. The conversation starts fine, goes to the Billing branch and then to the Aggregate branch just like it should, but then it falls out to 'Anything Else' instead of staying in the conversation path to the end - please see attached diagram below.

My agent code is down below. Please advise what is missing, I can see the conversation counter advancing each time.... why does the conversation end abruptly?

conversation ends abruptly

Here is my agent code:

require('dotenv').load();

var Botkit = require('botkit');
var express = require('express');

// Configure your bot.
var slackController = Botkit.slackbot();
var slackBot = slackController.spawn({
  token: process.env.SLACK_TOKEN
});

// Create the middleware object - for connecting with conv.
var watsonMiddleware = require('botkit-middleware-watson')({
  username: process.env.CONVERSATION_USERNAME,
  password: process.env.CONVERSATION_PASSWORD,
  workspace_id: process.env.WORKSPACE_ID,
  url: process.env.CONVERSATION_URL || 'https://gateway.watsonplatform.net/conversation/api',
  version_date: '2017-05-26'
});

// This declares the watsonMiddleware as the handler for the receive method
slackController.middleware.receive.use(watsonMiddleware.receive);


slackController.hears(['.*'], ['direct_message'], function(bot, message) {
  watsonMiddleware.interpret(bot, message, function() {
    if (message.watsonError) {
      bot.reply(message, "I'm sorry, but for technical reasons I can't respond to your message");
    } else {
      console.log("\nsprint-bot-slack.js > to the bot with message.context: " + JSON.stringify(message.watsonData.context, 2, null) + "\n");
      bot.reply(message, message.watsonData.output.text.join('\n'));
    }
  });
}); 

// Start the bot using Real Time Messaging APIs
slackBot.startRTM();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.