In slack how do i get the webhook information for a slack channel? - webhooks

there is existing code for dropping log messages into a slack channel:
"T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
if os.getenv(Constants.ETL_RUNTIME_ENVIRONMENT, "qa") == "qa"
else "T03NG233B/B019306HABC/P7QUsfXauVCABVxxiVXFid"
)```
but how did the code author locate the long string after the 'else' ?

Related

Send message As a reply to specific server's channel

I have 2 guilds and the BOT is in both guilds.
The Bot works like this.
When I send a message from guild 1, the BOT copies the message and sends it to guild 2.
The requirement of making a BOT is working well but I want to make it as a reply to the message when the BOT sends it to guild 2.
Here is the CODE
const guild = client.guilds.cache.get('881014432841490452')
const channel = guild.channels.cache.find(chname => chname.name === 'general')
channel.send(message)**
If someone knows please help me.
Thanks
You cannot make a message in the same time reply to a message and make that message appear on another guild. When you reply to a message it will be on the same channel as the original message.
The only solution you have is to send the message with the URL so people can click it and access the original message:
const guild = client.guilds.cache.get('881014432841490452')
const channel = guild.channels.cache.find(c => c.name === 'general')
channel.send(`Link : ${message.url}\nContent : ${message.content}`)

I just made a welcome and goodbye message for my discord.js bot but it doesn't send the messages to the required channels

Here's my code,
Welcome message:
client.on('guildMemberAdd', async member => {
if(member.guild.id !== "737222740305641472")return;
const channel = guild.channels.cache.get("750952211659620413")
if (!channel) return;
let data = await canva.welcome(member, { link: "https://imgur.com/a/BPTpkDT", blur: false })
const attachment = new Discord.MessageAttachment(
data,
"welcome-image.png"
);
channel.send(
"Welcome message here",
attachment
);
});
And my goodbye message's code:
client.on('guildMemberRemove',(member) => {
if(member.guild.id !== "737222740305641472")return;
guild.channels.cache.get('781737515421138984').send(`Goodbye message here`);
});
I'd like to make it clear that I dont get any error's in my console and that I've given the bot all the perms it needs to send messages.
Also, I've already declared my guild before, so that isn't supposed to be the problem.
Can anyone tell what I'm doin wrong?
As directed by this comment, it is appearent that you have not enabled privilliged intents for your application. For your application to listen to events such as guildMemberAdd and guildMemberRemove you would have to enable to Members Intent from the Discord Developer Portal. Here is what you would be looking for:
This can be found under
Your Application > Bot > ( Scroll down ) Privilleged Gateway Intents > Server Members Intent ( toggleable ).
This was a change introduced in the Discord API version v8 for the intents to be mandatorily enabled for such API requests.

Get message ID from reaction discord.js

Note: I am using discord.js V11, I know I plan on updating it to V12 next month after I unspaghetti my spaghetti code.
So I have no idea how to grab the messageID from a message that has triggered the reaction in the bot.
The way I want it to work is as follows: A user reacts to a message, any message, with the reaction programmed within the bot. The bot then grabs the message url that the reaction was given to, and then sends a message to a client.channels.get("id").
So I tried using this code but really couldn't quite get to where I needed to be:
client.on('messageReactionAdd', async(reaction, user, message) => {
if(reaction.emoji.name === "hm") {
let ticket = client.channels.get("CHANNEL_ID");
let ticketurl = message.url
ticket.send("Test confirmed" + ticketurl);
}
});
Figured it out!
I just needed to add this:
let ticketurl = react.message.url

How do I get notifications when a bot sends a message in Teams?

I developed a bot for Microsoft Teams using the Microsoft Bot Framework v4 Nodejs SDK (botbuilder-sdk for nodejs). We have implemented the bot in such a way that, when we receive data using a REST API call from one of our CRMs, the data is posted to the channels on Microsoft Teams. However, when I do that, we do not receive a notification on the devices. Has anyone faced such an issue?
I am saving the context state initially. Everytime we receive data from a CRM, I am incrementing the activity id of the message (to send it as a new message and not a reply) and sending it to Microsoft Teams using context.sendActivity().
When we receive that adaptive card, we do not receive a notification in the activity feed or on any of the devices.
I have gone through all the steps as you described above. I've also gone through the troubleshooting steps. However, it still doesn't give me a notification for the card. However, when I initiate a conversation with the bot, I get a notification when the bot responds.
https://i.stack.imgur.com/Bi4fc.png
https://i.stack.imgur.com/ab6uP.png
In this image, I get a notification when I get the TMS Bot started! message. However, I don't get a notification for the next two messages.
Edit: OP and I have exchanged a few emails to get this answered. This answer, as a whole, is good information for accomplishing Teams Proactive messaging, in general, but the main answer is in the last section, Simplified Code.
This is a long answer that covers many areas, simply because I'm not 100% sure I know what kind of notification you aren't receiving.
Troubleshooting
Troubleshooting Guide
Pay special attention to the many areas where notifications need to be enabled
In particular, the user may need to "Follow" and/or "Favorite" the channel to receive notifications from it
If a user has the desktop app open, they will receive the notification there and will not receive one on their phone unless they have been inactive on the desktop app for 3+ minutes. Otherwise, it's likely a bug in Teams.
Chat Notifications
If you've followed the Troubleshooting Guide linked above, your users should receive chat notifications. If not, you can try updating your MS Teams desktop or mobile client. As #KyleDelaney mentioned, it may be helpful to # mention users and/or channels
Activity Feed Notifications
You can also create Activity Feed Notifications. The gist of it is that you need to:
Include text and summary in the message
Include channelData that sets notifications.alert to true
This code will accomplish that:
const msg = MessageFactory.text('my message');
msg.summary = 'my summary';
msg.channelData = {
notification: {
alert: true,
},
};
return await dc.context.sendActivity(msg);
Result:
Note: If your bot only creates notifications and doesn't have conversations, you may benefit from creating a notifications-only bot.
Full Implementation Code
import * as adaptiveCard from '../src/adaptiveCard.json';
...
const card = CardFactory.adaptiveCard(adaptiveCard);
const activity = {
attachments: [card],
text: 'Test Card',
summary: 'my summary',
channelData: {
notification: {
alert: true,
},
},
};
await turnContext.sendActivity(activity);
Result:
Using the Teams Extension
There's a Teams Extension for BobBuilder V4 that's currently in Beta, but seems to accomplish what you need. I believe the reason you weren't getting notifications while using the above is because your bot is creating a new reply chain in the channel and not replying directly to a user. I believe you can do all of this without the extension (by manually editing activity/context properties), but the extension should make it easier.
Here's the code I used to get working notifications within a channel:
In index.js (or app.js):
import * as teams from 'botbuilder-teams';
[...]
// Change existing to use "new teams.TeamsAdapter..."
const adapter = new teams.TeamsAdapter({
appId: endpointConfig.appId || process.env.microsoftAppID,
appPassword: endpointConfig.appPassword || process.env.microsoftAppPassword,
});
Wherever you're sending the message:
import * as teams from 'botbuilder-teams';
import * as adaptiveCard from '../src/adaptiveCard.json';
...
const card = CardFactory.adaptiveCard(adaptiveCard);
const activity = {
attachments: [card],
text: 'Test Card',
summary: 'my summary',
channelData: {
notification: {
alert: true,
},
},
};
const adapter = context.adapter as teams.TeamsAdapter;
await adapter.createReplyChain(context, [activity]);
Simplified Code
OP and I have emailed back and forth a bit and the key issue is that he needed to add the trustServiceUrl code from below. Normally, this manifests itself with a 500 error, but in this case, it appears to not create notifications.. After significant testing, here's all you really have to do to send different notifications to different channels. It basically amounts to setting a couple of properties of turncontext.activity and trusting the serviceUrl. No touching activity ID or using the Teams Extension at all. My code below is how I sent messages from Emulator that could then send cards to different Teams channels:
public onTurn = async (turnContext: TurnContext) => {
const dc = await this.dialogs.createContext(turnContext);
const dialogResult = await dc.continueDialog();
// Route message from Emulator to Teams Channel - I can send "1", "2", or "3" in emulator and bot will create message for Channel
let teamsChannel;
switch (turnContext.activity.text) {
// You can get teamsChannel IDs from turnContext.activity.channelData.channel.id
case '1':
teamsChannel = '19:8d60061c3d104exxxxxxxxxxxxxxxxxx#thread.skype';
break;
case '2':
teamsChannel = '19:0e477430ebad4exxxxxxxxxxxxxxxxxx#thread.skype';
break;
case '3':
teamsChannel = '19:55c1c5fb0d304exxxxxxxxxxxxxxxxx0#thread.skype';
break;
default:
break;
}
if (teamsChannel) {
const card = CardFactory.adaptiveCard(adaptiveCard);
const activity = {
attachments: [card],
summary: 'my summary',
text: 'Test Card',
};
const serviceUrl = 'https://smba.trafficmanager.net/amer/';
turnContext.activity.conversation.id = teamsChannel;
turnContext.activity.serviceUrl = serviceUrl;
// This ensures that your bot can send to Teams
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
await turnContext.sendActivity(activity);
} else {
[...Normal onTurn Code...]
await this.conversationState.saveChanges(turnContext);
}
Note: To receive notifications, you and your users must follow the channel.
I have gone through all the steps as you described above. I've also gone through the troubleshooting steps. However, it still doesn't give me a notification for the card. However, when I initiate a conversation with the bot, I get a notification when the bot responds.
https://i.stack.imgur.com/Bi4fc.png
https://i.stack.imgur.com/ab6uP.png
In this image, I get a notification when I get the TMS Bot started! message. However, I don't get a notification for the next two messages.

How do I figure out which channels my bot is in?

Using MS Bot Framework, how do I figure out which channels my bot is in, on slack?
Is it possible, without doing something slack specific?
I have tried doing something with the message type BotAddedToConversation but without any luck.
Basically, I would like to write to a channel, without having a message to reply to.
In the Message object that you get in the Post function of your Api, the ChannelConversationId property contains the Channel.
public async Task<Message> Post([FromBody]Message message)
{
if (message.Type == "Message")
{
var channel = message.ChannelConversationId;
[...]
}
}

Resources