Post proactive messages in Slack conversations with Bolt for Java - slack

I'm trying to start a proactive conversation with a user using the Slack Bolt SDK for Java but I don't know how to get a client for the Bot token, this is my code so far:
Bot bot = ...; // with botToken, botUserId, botId and so...
ConversationsOpenResponse conversation = app.client().conversationsOpen(conv -> conv
.users(List.of(user.getSlackUserId()))
);
But every request I try to make returns with error=invalid_auth because it's laking the auth token (bot token in this particular case).
Every example I found relies on a context with a client tied to the installer bot.

Related

How to send a message to a thread (reply) using a Bot Framework SDK 4.18 Teams

Scenario:-
User A -> Types a message in Teams App (bot)
Now Bot has to reply to the same thread that user A has started in Teams App (bot)
I am able to send a new message in the Teams App (bot) - Not expected
The bot needs to reply to the same thread the user started - Expected
Did not find any reply method in the below documentation.. continueConversation creates a new message.
https://learn.microsoft.com/en-us/javascript/api/botbuilder-core/turncontext?view=botbuilder-ts-latest#botbuilder-core-turncontext-getmentions&preserve-view=true
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/conversations/conversation-basics
The bot cannot give the reply to the same thread that user started. This is by design behaviour.
Bot can reply to an existing message but it looks new message not like reply, call ReplyToActivity in .NET or session.send in Node.js. The Bot Builder SDK handles all the details.
If you choose to use the REST API, you can also call the /v3/conversations/{conversationId}/activities/{activityId} endpoint.
Ref Doc: https://learn.microsoft.com/en-us/microsoftteams/platform/resources/bot-v3/bot-conversations/bots-co...
If you wish you can suggest this feature on - Microsoft Teams · Community

Can a slack bot join automatically a channel?

I am building a slack application.
I added "incoming-webhook" to oauth scopes that let me choose the channel I want the App to post messages. However unless I ping the app in the channel to add it. I get a "channel not found" error.
Is it possible to add the app to a channel when installing app via oauth ? Without adding it manually by #app-name or /invite app-name ?
When you add an incoming-webhookscope to your app, the option to add a channel during authentication is specific to incoming webhooks not bot messages. So any messages you send via the incoming webhook will send to the channel you selected during authentication. Messages sent via [chat.postMessage][1] will require your bot to be a member of the destination channel, via invite. Incoming webhooks can only be linked to a single channel. You will have to create a new webhook for every channel you want to post to using webhooks. For that reason, I'd recommend using chat.postMessage instead. If you request the chat:write.public scope your bot will be able to post into any public channel without invitation.

How to send message activity from Web Chat Bot to Microsoft Teams channel

I have created a Echo Bot in c# using QnA maker which is working absolutely fine now I wanted to achieve a scenario where if user ask any question and bot unable to find related answer than this question must be sent on Microsoft Teams channel where except will reply to the same and that message will sent to the user.
So, Is there any way to send message user message to Microsoft Teams for expert reply. If you have any sample code for the scenario please feel free to mention.
As per your current requirement this is kind of handoff or human live agent connect.
The following way you can achieve posting a message in ms team ( Go through this article Send proactive messages to Teams channels and users ).
Send proactive messages to Teams channels and users ( Microsoft Bot Framework v4 )
The user should be part of ms teams ( Azure AD valid users ).
Suggestions : If you are using domain bot then human live agent or handoff concept is the best approach otherwise you can integrate bin search api or any other third party api for unanswered question.
As per your requirement you can use Graph API to send message to channel using below code
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var chatMessage = new ChatMessage
{
Body = new ItemBody
{
Content = "Hello World"
}
};
await graphClient.Teams["{team-id}"].Channels["{channel-id}"].Messages
.Request()
.AddAsync(chatMessage);
Please go through this documentation for more info.

Send a bubble into a teams meeting through bot framework

After downloading and running the sample project (Meeting Token Generator) I tried to create my own bot. So I followed the steps 2 and 3 (in the previous link) to create a new resource and a new bot channel registration. After this I replicated the method PostStatusChangeNotification (from visual studio project), that should sends a bubble, into a java function, on a springboot project.
So I used continueConversation method from BotFrameworkHttpAdapter to send the bubble.
There are these two problems:
As the docs (of method continueConversation): Most channels require a user to initiate a conversation with a bot before the bot can send activities to the user. So, how meeting token generator can send activities into a meeting chat without user conversation init?
Why bubble not showing when my bot send the activity? Only chat message works. I also tried to manually post (with postman) the same JSON payload generated by Meeting Token Generator (modifying the data to be modified), and I noticed that the bubble is shown only using Meeting Token Generator's bot.
So the same post request with a different bot's bearer token doesn't show the bubble, but only in-chat message. I really can’t explain it.
Hope you can help me, thanks.

Sending a message to users as a bot in bot channel of Microsoft Teams using the Graph API

I have created a bot by following the steps mentioned in the doc.I have authenticated user using oauth 2.0 (auth code grant) as mentioned in the doc and in reverse I got a access token. But when I send message to channel in the teams using (/teams/{id}/channels/{id}/messages) API the message was sent on behalf of me. But I want my bot as the sender of message. Here is the image of the message that I have sent using the above API. and is there any way to send direct message to user as a bot?
Instead of using the Graph, there's another approach using the Bot Framework itself, to send a message to a team channel, a group chat, or a 1-1 conversation. The code doesn't even need to live inside the bot itself, it just needs to leverage the bot framework under the covers (for example, I have several Azure Functions that pro-actively message users). This idea is called "Proactive messaging" and you can read more about it in the docs here.
You do need to get certain fields when the user first installs the bot though, or any time the bot receives a message. I've described that more at Programmatically sending a message to a bot in Microsoft Teams. You haven't said what language you're using, but there are examples for a bunch of them - I can send you links if you let me know what you're using.

Resources