![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Simplifies sending bot messages to slack. Slack-bot utilizes incoming webhooks in Slack to send messages. You can add the incoming webhooks integration and get your unique webhook url at: https://YOUR_TEAMS_SLACK_URL/services/new/incoming-webhook.
npm install slack-bot (--save)
var slackBot = require('slack-bot')(YOUR_WEBHOOK_URL);
To send a message, call the .send function:
slackBot.send(messageObject, callback);
The callback is optional and is passed three arguments:
A simple callback example:
slackBot.send(messageObject, function(err, res, body) {
if (err) return next(err);
console.log(body);
});
The simplest message object:
slackBot.send({
text: 'This message will appear in Slack!'
}, callback);
SlackBot defaults to the #general channel and to the username "Slack Bot" if those properties aren't passed in as in the example above, but can easily be set to whatever you like:
slackBot.send({
text: 'OMG look at this thing',
channel: '#hackers', // Can also be '@someone' for a direct message
username: 'Alert Bot'
}, callback);
The other most commonly passed in property is to provide either an icon_emoji or an icon_url to replace the avatar of the bot sending the message:
slackBot.send({
text: 'Put… the bunny… back… in the box.',
channel: '#onetruegod',
username: 'Nic Cage',
icon_emoji: ':niccage:' // You can upload custom emojis in your team settings
// OR
icon_url: 'http://i.imgur.com/VVoeZ.gif'
}, callback);
The message object can also take additonal parameters. An overview can be found here: https://api.slack.com/incoming-webhooks
For some advanced message formatting information: https://api.slack.com/docs/formatting
How to send rich messages to slack (with good examples of messsages): https://api.slack.com/docs/attachments
Slack-bot can also take an array of channels in the message object in order to send the same message to several people or several channels (or a mix of people and channels) all at once.
slackBot.send({
text: 'Do not go outside, zombies are out there!',
channel: ['#general', '@jon', '@charles'],
username: 'Zombot',
icon_emoji: ':zombie:'
}, callback);
In this case, the same message will be sent to the general channel, and to jon and charles as direct messages. When sending a message to multiple channels, the callback receives two arguments. The first argument is the error argument. If no errors occurred, the first argument will be null
. If one or more errors occurred, the first argument will be an array of channel names where the errors occurred. The second argument is an object whose keys are each channel the message was sent to, and the value is an object with keys err, res, and body containing the values returned from that particular POST
. If we were to send the above message to those three channels and no errors occurred, the object that would be returned to the callback would look like this:
{
'#general' : {
err: null,
res: RESPONSE_OBJECT,
body: 'ok'
},
'@jon': {
err: null,
res: RESPONSE_OBJECT,
body: 'ok'
},
'@charles': {
err: null,
res: RESPONSE_OBJECT,
body: 'ok'
}
}
It is important to note that any errors that occur when sending to multiple channels will not stop the sending of the message to the other channels. That way if an error occurs half way through, it won't stop the message from going to the remaining channels.
The reason the error argument passed to the callback is an array of channel names is so you can easily access all the errors that occurred in the returned object by using the values in the array as the keys in the object:
slackBot.send(messageObjectToMultipleChannels, function(err, object) {
if (err) {
err.forEach(function(channel) {
console.log(object[channel].err);
});
}
});
FAQs
Simplifies sending bot messages to slack.
The npm package slack-bot receives a total of 23 weekly downloads. As such, slack-bot popularity was classified as not popular.
We found that slack-bot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.