Create Interactive message from bot - slack-api

I want to ask an interactive question in slack using slackbot. I want to achieve the same functionality using slackbot which we can achieve using slash commands.
My slackbot is receiving an event which contains the username of the slack. I want my slackbot to ask a question to the user whether he wants tea or coffee.

Related

Teams bot, which approach to go for?

My use case requires me to integrate teams with an app. Whenever a message is sent from that app, a private channel will be created and the message will be sent to teams. I've been reading the documentation and it has only confused me further. Do I need to use graph or bot? Can I do this using only graphs or only bot?
It's possible to send a message using Graph API - see here for more: https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=http
HOWEVER, there are two ways to authenticate with Graph, either via an "application" permission (kind of like background service), or via "delegation", which means your app would work on behalf of a user. For this specific Graph endpoint, Microsoft mentions in the page that Application permissions are only allowed for "migration" (e.g. if you were building a tool to migrate from, say, slack to Teams). That means that you would have to use "delegation" which means the message would appear to come from a specific user.
As an example, instead of the message coming from "ABC Application", it would appear to come from "Syed Muhammad Ibrahim". If that's ok, then you can use Graph. If not, you would need to go the Bot route.

How do I start an Twilio Autopilot chat session without the user needing to greet the bot?

How can Twilio Autopilot chatbot initiate a session with a user without the user greeting the bot?
I've tried exploring using Twilio Studio to kick off the conversation, but our application requires that the first interaction in the sequence must be a Collection Action. I can't seem to kick off that Collection Action without the user having greeted the bot.
An example would be that every day we would message the user with a question: "How many bananas did you eat today?". The user would then respond and Autopilot would parse the data and send to our system. The question can't be hardcoded in Studio because it will be dynamically generated on a daily basis. The question must be a Collection Action.
Twilio developer evangelist here.
Welcome to StackOverflow!
You can initiate a session with the user without the user greeting the bot by connecting the trigger widget's Rest API trigger event to either a make outgoing call or send message widget, as shown below.
Then, if the call is answered or the message is sent, you can connect those actions to the Send to Autopilot widget.
Lastly, under the config section of your Send to Autopilot widget, put in the Collection task you want to run when the outbound call or message is initiated by your Twilio client and not the user.
Let me know if this helps :D

How to make your bot user reply with a simple help message using slack bot

I have created a slack bot and I want to send a general static help message to users when they send a direct message to my bot:
Should I subscribe to Events API? Or do I need to do this in another way? I couldn't find a clear answer for this.
There are two ways to do make your bot user reply to direct messages:
Events API
Real Time Messaging API
In my opinion the Events API approach is easier to implement since it does not require using WebSockets.
The basic approach with the Events API is:
You need an endpoint that can receive event requests from Slack and
react to it, e.g. by sending a direct message back to a user.
Subscribe to message.im event for your bot user
Note that a bot user already has all the required scopes for this with the bot scope.
In addition I would recommend to subscribe to app.mention for your bot user. Then it can also react to mentions in other channels.
Btw. that message you posted looks a lot like a review comment from the Slack team for a new app submission. I got a similar one for my last app and I solved it with the approach above. In general it looks like if you want to have a bot user in your app it needs to be able to respond to help request from users.

Is approval-based sign-ups possible with Slack?

Normally, I invite new members via. email, that I get from them individually.
Let's say I want to campaign publicly for volunteers to join our community, then what is the best approaches with various level of control?
It is not possible out-of-the-box, but you can develop a custom website, where people can apply for your Slack and enter the name and email address.
You can then forward their request for you to approve (e.g. a page with a table of all open requests where each can be approved or denied or an automatically generated email to you etc).
Finally you can auto-invite every approved user with his email address. The Slack API has an undocumented API function that allows that. Check here for my post about that method.
I have done a similar website for inviting people from a gaming community (Eve Online), where they have to first authenticate themselves with their game login before getting an invite to our Slack. It works pretty well. I made this website with PHP, but basically every server based script language will work.

How to join a Slack channel as a Real Time Messaging bot user?

channels.join is not allowed for bot users. I would like my RTM-using bot to listen to channels other than the one listed in the bot integration page.
I don't see a way to change the channels in the bot integration page:
Is this just a limitation of bots or am I missing something fundamental here?
I had the same issue and wasnt sure why my bot was only listening to certain channels.
Your bot will need to be invited to each channel by a user. Run this command within the required channel in the Slack app to do so
/invite #<your_bot_name>
Once in the channel they should then be able to listen to events.
This is still a limitation of bots as of May 2017 because of a bug that it introduces-- see paulhammod's answer at https://github.com/slackapi/node-slack-sdk/issues/26. The correct way to add a bot is the the slash command /invite #<bot.user> <channel_name> as #MattGifford pointed out.
However, #nafg introduced an interesting workaround. If you generate a personal API_TOKEN for your account, then you can use it to invite a bot.
For instance, in python one could run:
import slackclient
sc = slackclient.SlackClient(<PERSONAL_API_TOKEN>)
sc.api_call('channels.invite', channel=<channel_id>, user=<user_id>)
This will invite the bot to the channel. If you wanted to automate inviting your bot to new channels, you can look at event listeners in the API found at https://api.slack.com/rtm
As long as you allow your API_TOKEN to be used for that purpose, it seems that it would work as needed, albeit less convenient.
I haven't actually tried this but I would expect that you can first call channels.join on behalf of an actual user (e.g., yourself), then call channels.invite as that user to add the bot to that channel. I expect that is allowed, and it would then allow the bot to interact with that channel. This way you can automate everything.

Resources