MS Bot Framework Direct Line API 3.0: Get starting message - azure

I published a bot using the Azure bot framework to the Azure cloud servers, and made an application that uses the Direct Line API 3.0 to send user responses and receive bot messages through HTTP requests. Everything works except that I'm not sure how to get the starting message of the bot at the start of the conversation. I open the conversation with the /v3/directline/conversations endpoint, but I'm not sure how to receive the first message of the bot (that is normally sent without any user interaction). A message request after opening the conversation doesn't include any bot responses, but the next message request after sending the first user input includes the first two messages of the bot (starting message and response to the user).
EDIT: From reading this I came to the conclusion that it will be easier to just use a custom event as a trigger for the welcome message. I updated my bot as follows to reflect this within bot composer, adding a new CUSTOM event trigger with a test response message:
However, I still can't seem to trigger this event via the Direct Line API. Currently, I send a request as follows, following the event activity structure:
{
"type": "event",
"channelId": "directline",
"from": { "id": "UnityUserId", "name": "Unity User 1" },
"value": "test",
"name": "welcome"
}
I then get a response with ID, normally indicating that the request was successfull. However, upon requesting the bot response messages, I get the following:
{
"activities": [
{
"type": "event",
"id": "5FZsHpWBxm1hjhWQYY7gr-eu|0000000",
"timestamp": "2022-04-09T14:39:15.90169Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "UnityUserId",
"name": "Unity User 1"
},
"conversation": {
"id": "5FZsHpWBxm1hjhWQYY7gr-eu"
},
"value": "test",
"name": "welcome"
}
],
"watermark": "0"
}
Indicating that the bot has no responses, which doesn't seem quite right when looking at the bot composer screenshot above. Is there something wrong with my current method?
Regards

The onMembersAdded event usually does the trick. Sample code is in https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-send-welcome-message?view=azure-bot-service-4.0&tabs=csharp

I thought I remembered seeing the bot's welcome message when using Direct Line, so I tried to quickly repro it again. I connected a simple echo bot via Direct Line. Then I created a conversation, sent a simple message, and then retrieved all activities (all via REST calls), and the bot's welcome message was indeed present in the response, as you can see in this screenshot:
Perhaps you should use these Direct Line 3.0 API reference docs as opposed to the one you linked above. I followed these steps using the basic Echo bot sample, Postman, and a bot resource in Azure for simple and easy testing, but you could use a full application if you wish.

Related

Telegram bot webhook send only commands

I'm building a telegram chatbot in nodejs that will work on webhook. Currently, bot hits my webhook URL with every message in chat. Is it possible to only push payload on command execution for the bot?
So I would like only to get the payload from the chat when the user executes /test command and any other messages in the chat should not git to my URL.
#Edit
Current setup of privacy
'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username.
'Disable' - your bot will receive all messages that people send to groups.
Current status is: ENABLED
I want to use bot in groups and in direct chat with bot - me so I can test things.
I created a test group added the bot and whatever I type into the group I can see in logs of the Webhook URL. So no matter if its /test or some text it's beeing pushed
#Edit 2
This it what I receive in my webhook URL (normal chat text, and bot command)
{
"update_id": 1,
"channel_post": {
"message_id": 65,
"sender_chat": {
"id": -1,
"title": "Tssos",
"type": "channel"
},
"chat": {
"id": -1,
"title": "Tssos",
"type": "channel"
},
"date": 1,
"text": "test"
}
}
{
"update_id": 1,
"channel_post": {
"message_id": 67,
"sender_chat": {
"id": -1,
"title": "Tssos",
"type": "channel"
},
"chat": {
"id": -1,
"title": "Tssos",
"type": "channel"
},
"date": 1,
"text": "/test#TESTss_bot",
"entities": [
{
"offset": 0,
"length": 23,
"type": "bot_command"
}
]
}
}
You have to use #BotFather to set your bot privacy:
Send /mybots command to #BotFather
Select your bot by its username
Select Bot Settings
Select Group Privacy
Enable or disable your bot's privacy
If Privacy Mode is enabled, your bot only receive messages which are start with slash /
Alright, so I found the answer to my problem.
I was adding a bot as an administrator to the chat that's why he was sending all messages. Admins bot will push all chat messages.
Adding a bot like a normal user solved the issue and now I only receive /command updates.
Privacy mode is enabled by default for all bots, except bots that were
added to the group as admins (bot admins always receive all messages).
It can be disabled, so that the bot receives all messages like an
ordinary user (the bot will need to be re-added to the group for this
change to take effect). We only recommend doing this in cases where it
is absolutely necessary for your bot to work — users can always see a
bot's current privacy setting in the group members list. In most
cases, using the force reply option for the bot's messages should be
more than enough.
Docs

Is it possible for a slack bot to edit the message on basis of a emoticon?

I want my slack bot to edit the original message (basically modify it).To trigger bot i would like to use an emoticon.
so the flow would be user post the message -> if user wants to use bot press a reaction -> once bot is triggered modify or edit the message with the custom content of bot.
for trigger i think this the API i would need https://api.slack.com/methods/reactions.get but is this even possible?
The api you have mentioned is for fetching the reactions associated with a message/post.
What you actually need is an event to be captured when a reaction is added to the message.
Here is the api that solves the purpose:
https://api.slack.com/events/reaction_added
You can now implement the business logic based on the event payload.
Sample Payload:
{
"type": "reaction_added",
"user": "U024BE7LH",
"reaction": "thumbsup",
"item_user": "U0G9QF9C6",
"item": {
"type": "message",
"channel": "C0G9QF9GZ",
"ts": "1360782400.498405"
},
"event_ts": "1360782804.083113"
}
To update the message, you can use chat.update api:
https://api.slack.com/methods/chat.update
you'll need : token: 'bot token' or 'user token' with required chat:write scope channel & timestamp details : you can find in payload of 'reaction_added' payload.
Note:
You cannot edit a message sent by another user, unless you have the 'User token'. https://api.slack.com/authentication/token-types#user

Update message card in Teams via webhook connector

I have a build machine from which I want to post updates in Microsoft Teams. I created a webhook connector for my channel in Teams and I can send a simple POST request to the webhook url to post a message card in Teams with this json payload:
{
"#type": "MessageCard",
"#context": "http://schema.org/extensions",
"summary": "Build Status",
"sections": [{
"facts": [{
"name": "Status",
"value": "<build status>"
}]
}]
}
Now I want to update the <build status> value as the build progresses and maybe add another fact with download link when the build is finished. Is it possible to update an existing card once it is posted? It seems like a common use case to me, but I was not able to find an answer to it. There are some blogs about updating card as a result of an action, but I don't have or want to have any actions. And obviously I don't want to keep adding cards for the same build process.
Currently update card via web-hook is supported in teams. Could you please Raise a user voice
Sorry, I jumped the gun on that. It appears it isn't supported from webhooks.
https://techcommunity.microsoft.com/t5/microsoft-teams/refresh-cards-not-working-in-teams/m-p/93282

Directline API message to Microsoft Bot

I have created the bot in azure services using LUIS, which used as chatbot and can create conversations using dialogs.
At some point, I am trying to push messages to chatbot using Direct Line API 3.0, I'm using Postman to send the messages to bot.
I followed the instructions from this page, https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-service-4.0
I'm able to send message to the conversation as bot, below is the image I sent message from Postman and got successful response.
But my issue is, after the message is sent, the bot tries to analyse even though it's not user message. Bot starts to send message from default message handler like below,
Even after sending the message successfully, my bot triggers the default message handler, which is expected only to happen for user messages but not for bot messages.
Also, I have checked with webchat channel, which it doesn't trigger this default message handler. This is happening only in DirectLine API, can anyone help me on this.
Instead of sending the message as type "message", you should send it as "event".
This way your MessagesController will see it as an ActivityType of Event instead of Message and you can process however you want without spaghettifying your actual message handling
If you want to send different kinds of event to make it even easier, then you can 'name' you event by supplying the 'name' field with a value in your json.
Third, if you need to include data with the message, you would supply a value in the 'value' field of your json.
The github page for the standard webchat client has some great information on sending events. It might shed a bit more light on the json.
You can read more about the 'event' activity type here
You message json would look something more like this:
{
"type": "event",
"from": {
"id": "user1"
},
"name": "theEvent",
"value": "someDataMyBotNeeds"
}

Unable to trigger event from webhook - api.ai

I need your help with the using of events for communication from webhook to demo chat (https://snag.gy/6tfGEZ.jpg) of api.ai. I have already test in telegram too and it does no work either.
My flow is the following:
The user request something from the api.ai web demo chat. for instance: “Hi, I need my access code”
Api.ai gets the intent and send it to my webhook.
My webhook starts an asynchounous operation to process user request (it could take more than 6 seconds) and returns “We are processing your request please wait a few seconds” to api.api therefore the user will see that message in demo chat.
After the asynchrounous process has been finished the next step will be call POST https://api.api.ai/api/query?v=20150910 with body
{
"event": {
"name": "result_event",
"data": {
"code": "ABDDRR787545HHTTU4545454"
}
},
"timezone": "America/New_York",
"lang": "en",
"sessionId": "a77875da-4bd5-db26-dce2-e42439d4fbde"
}
result_event already exists inside an Intent that contains the response “Your request was processed. Here your code: $code”.
The idea here is the user get the respond to his request for instance: “Your request was processed. Here your code: ABDDRR787545HHTTU4545454”
Althought I get a successfully respond of (https://api.api.ai/api/query) called from my webhook the user don’t get any response in the demo chat.
This is the screen (https://snag.gy/qN3tTC.jpg) of the intent with my event in api.ai.
What do you think I’m doing bad ?
Thanks in advance
Events in API.AI are calling methods for a specific intent. it does not trigger anything so you can not get any triggered for you web-demo bot.
this will work if you can make a custom html bot where you can call events endpoint to get the json data and show it in your html bot.

Resources