BadArgument:Security token not valid for this conversation - node.js

I'm trying to use Direct Line API of microsoft bot framework,
Following steps are followed.
Got Conversation Id from application(running on node.js)
[conversationId123]
Create Conversation Token from postman
https://directline.botframework.com/api/tokens/conversation
[ConversationToken456]
Get Conversation Messages using conversationId123 & Authorization header using ConversationToken456
https://directline.botframework.com/api/conversations/conversationId123/messages
I receive
BadArgument:Security token not valid for this conversation
Did I miss something?

Hard to know what's going wrong without seeing the whole flow; though the error indicates that the token is invalid.
Here is a DirectLine sample using Node.js. You might want to use it as the baseline for your sample and I'm pretty sure you will find out the error.

I think before sending a message to the BOT you should call the URL stream that returns from the initial "Start conversation" POST request. At least that appears at the documentation
In my case, using C# I'm able to retrieve a token, then message ID and even request the bot to send me a list of activities, but I'm unable to send a message (the POST request never comes back with an answer)

Related

Facebook Messages RESPONSE call working for my testing team, but not for FB testing team

I am creating a messaging app using Facebook messenger. I have been testing it thoroughly with my own account and another "tester" account. It works as expected for the two of us.
When submitting it for approval, the Facebook testing team messaged our page, but I received a ((#-1) Unexpected internal error) message when calling the RESPONSE api to reply.
Any ideas? I find it hard to believe this is an error on Facebook's end, but this is what's showing up for me.
Thank you in advance!
Detailed error message:
code:-1
error_subcode:2018012
message:(#-1) Unexpected internal error
type:OAuthException
I tried re-submitting the API call, but received the same error. I checked to see if it would work with another Recipient ID (my own), and it did. I'm not sure if this is a matter of approvals from Facebook's end, and if it's one of those cyclical situations where 'they need to approve me for it to be approved' or not.

How to use the Discord JS Client without logging in?

I have a service that listens for certain updates and then uses a Discord Bot to post a message on a channel. A random example: every time a team scores a goal, post a message in a channel. I got an email from Discord to reset my bot token because there were too many logins.
As you know, in order to use the Bot you use the client.login("XXX") method. So every time there is an update my service initializes the bot and then sends a message. My assumption is that it has to do with me calling client.login("XXX") for every update. Since my service runs serverless, I can not keep the service up.
Is there a way to make the bot post a message without having to use client.login("XXX")? Or can anyone suggest any strategy to make this logic work?
That is not possible as a bot cannot do any actions without being logged in, it sounds like channel webhooks would fit your needs better.
You simply generate a webhook link in a channel which you can then post messages to through a post request.
You can read more about webhooks here
And you can read more about the required paramters and how to format a POST request to the webhook here

How to create a bot in lex/azure that respond in slack threads?

I have created 2 chatbots using AWS lex and Azure bot framework each. I have integrated them with slack and they respond to the mentions in channels.
Currently, the bot responds as a new message however I want it to respond in the slack thread of the original message posted by the user. I tried to look for articles in various places but could not find anything helpful. Does anyone have any idea on how to achieve this or a reference to a GitHub repo for a sample?
Since you are able to post replies, I am assuming that you are using chat.postMessage API.
https://api.slack.com/methods/chat.postMessage
To send the reply as a thread, all you need to do is that add thread_ts argument in the api call.
(Provide original message's ts (timestamp) value to make this message a reply.)

Slack: Bot name in sent messages

I created a bot named "esmeralda". When I send a message to Slack with the token generated for this esmeralda, the message just appears to be from "bot", not "esmeralda".
Can I do something so that the message will be shown to be sent by "esmeralda" instead the "bot"?
I'm guessing you're using the Web API and therefore the chat.postMessage method?
I'm further guessing that you're not passing as_user=true as one of your parameters. Try doing that.
(If my guesses are wrong, please include the actual details of what you're doing: at least tell us what API you're using, what method you're calling, and what parameters you're passing. Ideally share code.)

How to get dynamic response based on the result of the action performed in Api.ai?

I'm trying out few examples in Api.ai console. I see there are examples where the agent responds by using the values that are extracted from the user query or from the context. But is there a way to display response that is formed using the output of the action performed?
For example -
User: Is my pizza order confirmed?
Action: check order status
Response: Yes, it's confirmed (or "No, it's not")
You will have to use some custom webhook to do this, either integrating with a 3rd party API or will a server side call of your own to a database- in this case the webhook would take the user's ID and query if their pizza is ready or not, and this would then be passed back to API.ai.
Here is an example using a 3rd party webhook to do what you are asking:
https://github.com/api-ai/apiai-weather-webhook-sample
Yes you can do this with webhooks.
Typically, you would save the status of the order in your db, then you could have an intent that would:
Understand the query of your user (Is my pizza order confirmed)
The intent would call your webhook
the webhook would return the status order.
Api.ai would then give the answer.
When you use webhooks you need to return the speech response, the displayText, optionally the data that your apps need, the contextOut and the source.
I guess you would also need to have implement some context in api.ai so that you could now who is asking about the satus of the order. You would then be able to use the sessionId
Matt is correct here. You must use a webhook. Unfortunately the documentation from API.AI is currently very poor. Here's a screenshot example of an incoming post request. My message function will return an object with a desired response. In this case, I am using a Telegram chat bot. If you are not using any messenger, you can drop the data key: value. FollowupEvent is also optional.
Node.JS code with Restify
On your API.AI intent, make sure to check off Webhook. If you end getting the text response 'Broken' here, then something went wrong and you should check your error codes.
API.AI intent
And lastly, under the fulfillment tab, make sure to enable the webhook and point it at the right endpoint.

Resources