Slack API - Number of messages sent by a user - slack

i am trying to use the API to get the total number of messages posted by each user during a certain period. Ideally, I would be able to break the number of messages by the type of channel (public, private, direct messages.) Is this possible? I am looking through the API documentation but haven't found anything. I would be using it to create a script that would automatically generate weekly activity reports.
Thank you for any advice you can provide!

There is no special endpoint for this information as far as I know, but you can generate something similar yourself by looping though all channels and counting the message per user, e.g.
Get list of all channels with conversations.list
Get history of each channel with conversations.history
Count messages per user
Of course your results would not include message from channels, that your bot has no access too (e.g. some private channels, direct message channels).

Related

Is conversation Id in slack immutable?

I need to send messages to channels. Documentation give advice to receive all channels, pick you channel by name and after all send message by conversationId.
I want to cache the value of conversation id. But I want to be sure it won't be changed.
Documentation says
Recently we began preserving the channel ID of channels converted from
public to private.
So we can conclude, that it is immutable now
https://api.slack.com/changelog/2018-09-more-reasons-to-be-a-conversations-api-convert

MS Teams: how should we tell if an activity event comes from a bot?

we have a chat bot that seems to be receiving messages from another bot. we'd like to ignore these messages, as responding to them leads to an infinite loop of ping pong between the two bots.
we were hoping to rely on activity.from.role as documented here, but it seems like that field is never set.
activity.from.id looks something like 28:app:00000000-dfae-4fe1-a068-80fe8fc61f2b_62b732f7-fc71-40bc-b27d-35efcb000000, and we are thinking that the only way to identify the account as a bot is by detecting the :app: in these IDs. this is sub-optimal, as this ID format is not part of the official API and could change at any time.
that said, how should we detect if an activity event is coming from a bot?
If you've to deal with potential bots from outside your organisation, a simple way could be to keep a dictionary of few last text exchanges indexed by userId or UserName in the Activity object. Then, at each POST received by your bot, check if the received text match fully one of the precedent message entries in this dictionary. If it is the case, then mark the related userId/UserName as a candidate for the bot role but continue to check further text exchanges in case a non bot user just said hi twice.
If the few following further exchanges doesn't meet anymore the full match requirement, unmark the userId/UserName as a potential bot. If there is marked UserId/UserName as candidate for bot role, apply the bot role to them if there's no more further exchanges past the full match entry or after a delay of your choice. For the latter, it might be useful to provoke a last text exchange after the delay to decide.
For the Watson/Eliza kind of bots, i recommended to check the speed of the exchanges, as far as i know, no human being can exchange more than twenty messages per second.

Get list of channels a user is a member of

Writing a slack bot and I would like to be able to get a list of all the channels my bot is a member of. One way to do this is to call https://slack.com/api/channels.list, get a (potentially large) list of all channels and then search for the channels that the current (bot) user is a member of. This works fine, but seems very heavy handed.
Is there a better way? To get just the channels that a given user is a member of?
I think users.conversations is what you're looking for. Without additional params it will return all public channels the calling user is a member of.
No, there is no shorter way to get this information.
Actually, Slack recommends to use the new conversations methods for this task, since the members property in all other methods, e.g. channels.list has recently been changed to only return a truncated user list. See here for details.
With conversations you have to make an additional call per channel to get all channels a user is a member of. However it will work with all types of channels (e.g. public channels, private channels) at the same time.
The basic approach is:
Get the list of all conversations from conversations.list
Get the list of members per conversation form conversations.members.
So if you want your Slack app to be future proof and also work with large number of users better use the conversations methods for your task.
FYI you can now list user channels/conversations using:
https://api.slack.com/methods/users.conversations

Telegram - Counting messages

I'd like to count the messages of a specific conversation in Telegram. There should be a way using Telegram Desktop and using the debugmode to save the log information (see https://telegram.wiki/desktop/tdesktopcountingmessages). Unfortunately the count-tag is missing in most cases. Any other ideas?
The easiest way to do this currently is by searching for '+' in the conversation of interest. This will retrieve all messages and you can see the count from the search results. See attached image for an example. This conversation contains 32 messages in total.

How to resend failed SMS in bulk

Twillio failed 150 SMS due to lack of funds in the middle of a campaign. Is there a way to resend those 150 messages in bulk? Thanks!
If you don't have a queue on your side, the easiest way is to use the API to find the list and resend as appropriate:
You can use the SMS Messages List Resource - http://www.twilio.com/docs/api/rest/sms#list - to get a list of messages within a certain date range from a certain number.
From there, you'll get back a list which you can iterate over. For each of those, check the "status" parameter for the "failed" value - http://www.twilio.com/docs/api/rest/sms#sms-status-values
I would recommend making a list of those, looking at them yourself to make sure the numbers are what you expect and then reload them send via your normal means.
On another front, we have auto-recharging specifically to prevent scenarios specifically like this. If that's not turned on, you should enable it so this doesn't happen again.
Disclosure: Twilio Employee here

Resources