How do i make a bot check if a message was sent in a certain server? (discord.py) - filter

Not much to it really.
I just have a bot which has a chat filter function which i only want to run on my friends server. However i have the bot in multiple servers. What do i put before the code to make it only run in a certain server?

The most straightforward way would be to just put a conditional in your on_message definition that prevents it from taking action if the message wasn't from the given server.
async def on_message(message):
WHITELISTED_SERVER_ID = '01234567890123456789'
if message.channel.server.id == WHITELISTED_SERVER_ID:
// do whatever the bot does
You can adapt that to however your bot is designed. There are also other concerns (e.g. if the message is from a direct message, message.channel.server won't exist), but that's the gist of it.

Related

How to make Slack app send a private message via an incoming webhook to someone specific?

I created a Slack app that sends a series of interactive messages to a channel. In my Slack API dashboard, I see that I can create and remove hooks. Right now the hook url that I have set up in my code is the one for the Slackbot channel.
But the problem is that such a message only gets sent to me.
I want to send the Slackbot messages to Alice in situation A, and to Bob in situation B. Not just to myself, the guy who configured the app.
What's the best way to do this?
I would suggest that you should not use hooks for this. A more sane way to do this right would be via chat.postMessage Web API method which is documented here!
This is because hooks are tied to specific conversations and that approach quickly hits a wall on what it can really achieve, especially messaging different people. Once you start using the web API it's pretty simple. Just ask for the scope during app installation (remember to add that scope in your dashboard), subscribe to the event in your API dashboard and then you are good to go.
Everytime you send a message via that method, Slack will send you a payload which you can use for testing and logging etc.
You can see all the different ways to message programmatically inside Slack here.

message bot for Microsoft Teams

I'm wondering if it's possible to create a program that sends a scheduled message in a Microsoft Teams channel?
It would preferably be undetectable to be a bot and seem like a normal message. If this is possible, is it possible to put if and else conditions in the program: for example, someone says 'hello' then the program responds with 'hello'.
Thanks.
If you want the message to come as if it was sent by you, you'd need to use the Graph API, something like this. It seems like you don't want to appear to be from a system (e.g. from a bot), but if you don't mind that in the end, you can also look at Incoming Webhooks, which are easy to use and don't need Graph or a Bot.

Making bot have different presence in different servers

I'm trying to make a discord command where users can change what my bot is playing, but it changes for all servers and I don't want that. Is there a way to make it so that it only changes for the server that the user is sending the command from?
So far all I have is this
games={}
#bot.command(pass_context=True)
async def game(ctx, name):
server=ctx.message.server
games[server.name] = await bot.change_presence(game=discord.Game(name=name))
This is not possible as a Discord bot is only considered to have one websocket. You could make a loop and asyncio.sleep(time) to change the presence over time. Hope that helps!

Need suggestions in getting the conversation details

I am creating a bot using MS Bot framework - NodeJs. The below information needs to be captured for logging (Using the bot.use method i.e. IMiddleware).
Receive:
a. UserId
b. UserInput (text)
c. ConversationId
Send:
1. Name of Intent or dialog name that handled this (that handled the user input text)
2. Bot output text
3. ConversationId
4. UserId
I am unable to get the required detail for the 'send'. Can anyone provide me some suggestions on this.
Thanks.
I believe your main struggle is to log the name of intent or dialog. You won't know it in your send middleware if you haven't captured it during the routing phase. Once the Bot Framework figured out where to send the incoming message, it just invokes that function.
These two articles may help you get what you want. Just recently I played with capturing the conversation's breadcrumbs and also logging a full transcript:
http://www.pveller.com/smarter-conversations-part-3-breadcrumbs/
http://www.pveller.com/smarter-conversations-part-4-transcript/
If you need to build a reliable capture engine, I would suggest that you didn't use the session.privateConversationData like I did and instead built your own storage/log infrastructure to push the events to. Just stream them out with a timestamp and conversationId and reconcile on the other end later. The asynchronous nature of everything the bot framework does internally will be haunting you along the way so that's why. Plus, once you scale out beyond testing on a few users and your bot spans multiple processes, you will be out of the single-threaded event loop.

creating a slack bot using slack-api ruby gem not responding back as a DM

I have set up a slack bot using slack-api and the real-time-messaging api.
Here is the abbreviated setup:
client.on :message do |data|
d {data}
bot_response = BotResponse.get_bot_response(data['text'], "session_slack")
Slack.chat_postMessage channel: data['user'], text: "#{bot_response}"
end
client.start
With this version of the postMessage, the response comes from Slackbot, not my bot (named kaya).
Goal: I want to respond to come as a DM from the bot it was sent to.
When I change the channel to data['channel'], the response comes as DM from my bot kaya, but gets into an endless loop.
How do I have a non-endless loop DM response?
NOTE:
I think I see how it is happening: by selecting the bot as the "channel" the bot is responding to it's own response back to me, as if it were another user talking into the "bot's" channel. But I can't tell how else to have the response come from my bot, not slackbot.
I believe you need to include the username parameter set to the bot name per the api: https://api.slack.com/methods/chat.postMessage, or you need the as_user option.
This mixes the Web and the RealTime Messaging API. You get a message from the RealTime Messaging API then you are using the Web API to post back. The answer of including as_user: true is correct, but you should instead use the RTM API to send the message back.
Try https://github.com/dblock/slack-ruby-client instead that cleanly separates the two. Sending a message back as the bot looks like this:
client.message channel: data['channel'], text: "Hi <##{data['user']}>!"
To avoid DM loops, make sure you're not responding to commands that you emit. There're other ways, like ignoring bot messages, but it's not as reliable.

Resources