Get the nth activity that the user sent to the bot - botframework

I want my bot to send the user a message after every 3 messages(activities) the user send. Is there a method in the bot framework to detect the number of the activity sent or the count of all past activities?

A bot is stateless by default, however you could save the 'activity counter' in the user / conversation data. Retrieve and increment this counter at every incoming message.
Microsoft Docs: Save user and conversation data

Related

Is it possible for a Slack bot to listen to user #-mention events?

In Slack, users are pinged when they are #-mentioned in a channel. Is it possible for a bot or app to receive an event when a user is tagged this way? It doesn't seem to be on the Event Types API.
The app_mention event is meant to handle just this scenario.
Any time a message references your app by its bot username (e.g. #myBot), your app will receive this event along with metadata like the user ID who wrote the message, the text of the message, timestamp, and channel ID.

How to get message id of sent message Bot Framework (Teams channel)?

I am using Bot Framework SDK for Javascript. My bot is connected to the Teams channel. Right now I am saving every outgoing and incoming message from my bot to the DB.
But I want also to save reactions of user to my messages. That is why I am using TeamsActivityHandler and onReactionsAdded method (link). In the docs there is written that replyToId field of turnContext is the id of message user is reacting to.
But when I am sending message to the user via turnContext.sendActivity() I don't know the internal id which will be given to this message on Teams side, that is why I can not pair reaction to the message stored in my db.
So my question is, How can I get the id of the message after sending it via turnContext.sendActivity() which will be later send in replyToId field to onReactionsAdded handler?
In other words I want to collect feedback (via reactions) on the messages my bot is sending to the user and save them to my DB (messages and reactions).
Actually it turns out (after some tries) that turnContext.sendActivity() returns ResourceIdentifier which contains one field id and that id is the id which will be given to the message on the Teams side.
EDIT:
For some ResourceIdentifier is empty when message sent to Teams is for example hero card. So this does not completly work.
You can access the activity param after the await command to get this ID. So if we have our response in a variable reply (could be text, hero card etc...) we can get the ID after the await (inside the override async Task OnMessageActivityAsync method)
await turnContext.SendActivityAsync(reply, cancellationToken);
string responseMsgId = reply.Id;

How can i ignore user messages in MS Bot framework using direct line channel

I have created a bot in one scenario it will call an API and it will take same time to get the output from that API, if in between user type anything it will start working on the text which user sent recently. I want till API output is not received, if user sent any messages it will get ignored.
If your bot is integrated into some app then you can actually disable the send button until you receive an answer for the previous question.
I am setting one session when user is requesting to talk with Live Agent, Then i am checking if that session is in progress and any new message is coming from user then i am just ignoring them.

Design Slackbot service to send automated messages

It is my very first time to write a slack bot and i am wondering how to design it.
The bot supposed to be available and respond to end-users' messages immediately.
The thing is that I need that the bot will also send schedules messages to registered users with automation results.
Use case example:
A user sends a message to the bot and registered to a service that
will check for changes in X. On a specific interval, my backend will
call an automation that checks for those changes and will send a
message to the user with the results.
What will be the best practice for this scenario?
Here is a basic outline.
1. Basic setup
Slack app with bot user
Database
Scheduler (e.g. local CRON service, or web-cron like cron-job.org)
2. Registration
Use Events API to listen to messages from users send via mention (app_mention) or direct message (message.im)
You app needs to store the received "registration" from each user in a database
Respond to user request directly if needed with chat.postMessage
3. Scheduled response
Scheduler calls your app
Your app check if responses are due with a database query
If yes: App sends responses to users via chat.postMessage (but not more than one message per sec due to rate limiting)

Find the address of a specific user using Microsoft bot-builder

I would like to open new conversations with users using the Microsoft Bot Builder on the Skype for Business channel. The only information I have is the user id (sip:user#domain.com)
In all the examples I could find, it is needed to save the conversation id/address of a user in a previous conversation to send a new message to this user.
How to create a new conversation as a bot to a user knowing only his id?
Thanks
Like you stated the userId is required to send a message to the user. A new conversation can be created by the framework but ultimately, you can't do anything without the userId and to obtain this the user has to contact your bot first. This is only true for channels like Skype. Other channels like E-mail just use the email address as an id. Skype uses a GUID as the id for their users. This is done so bots can't randomly add themselves to any user on Skype. Source
This doesn't mean you have to necessarily wait for the user to start a conversation. Whenever a user adds a bot to their contact list an event is send to the bot. This is the ContactRelationUpdate event. It warns the bot that a user has added the bot and the bot can then respond accordingly. Once this event is thrown you can obtain the userId from the activity and do whatever you want with it. Source

Resources