Get channel list in Slack - node.js

I'm using Incoming webhooks to send message to the channel. I decide the channel in JSON format.
var message = {
"text" : "text",
"channel" : "#general",
"username" : "me"
};
How can I get the list of channels in Slack?

You would need to use the Web API. Incoming webhooks are insufficient for this.
(Specifically, you want channels.list.)

Related

Is it possible for a slack bot to edit the message on basis of a emoticon?

I want my slack bot to edit the original message (basically modify it).To trigger bot i would like to use an emoticon.
so the flow would be user post the message -> if user wants to use bot press a reaction -> once bot is triggered modify or edit the message with the custom content of bot.
for trigger i think this the API i would need https://api.slack.com/methods/reactions.get but is this even possible?
The api you have mentioned is for fetching the reactions associated with a message/post.
What you actually need is an event to be captured when a reaction is added to the message.
Here is the api that solves the purpose:
https://api.slack.com/events/reaction_added
You can now implement the business logic based on the event payload.
Sample Payload:
{
"type": "reaction_added",
"user": "U024BE7LH",
"reaction": "thumbsup",
"item_user": "U0G9QF9C6",
"item": {
"type": "message",
"channel": "C0G9QF9GZ",
"ts": "1360782400.498405"
},
"event_ts": "1360782804.083113"
}
To update the message, you can use chat.update api:
https://api.slack.com/methods/chat.update
you'll need : token: 'bot token' or 'user token' with required chat:write scope channel & timestamp details : you can find in payload of 'reaction_added' payload.
Note:
You cannot edit a message sent by another user, unless you have the 'User token'. https://api.slack.com/authentication/token-types#user

DialogFlow - send custom payload for telegram such as video

Folks.
I need to send video file from dialog flow as URI to telegram user.
Tried:
{
"telegram": {
"video": "https://"
}
}
Tried to guess JSON format for fulfillment message via "payload" but nothing works.
And I could not find documentation about the required format.
How to do it ?
So apparently you cannot send a video in Telegram. According to doc the only supported rich responses are Image, Card, Quick Replay, and Custom Payload (which includes text and hyperlink). If you want to send the link here's the format of custom response:
{
"telegram": {
"text": "You can read about *entities* [here](/docs/concept-entities).",
"parse_mode": "Markdown"
}
}

Directline API message to Microsoft Bot

I have created the bot in azure services using LUIS, which used as chatbot and can create conversations using dialogs.
At some point, I am trying to push messages to chatbot using Direct Line API 3.0, I'm using Postman to send the messages to bot.
I followed the instructions from this page, https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-service-4.0
I'm able to send message to the conversation as bot, below is the image I sent message from Postman and got successful response.
But my issue is, after the message is sent, the bot tries to analyse even though it's not user message. Bot starts to send message from default message handler like below,
Even after sending the message successfully, my bot triggers the default message handler, which is expected only to happen for user messages but not for bot messages.
Also, I have checked with webchat channel, which it doesn't trigger this default message handler. This is happening only in DirectLine API, can anyone help me on this.
Instead of sending the message as type "message", you should send it as "event".
This way your MessagesController will see it as an ActivityType of Event instead of Message and you can process however you want without spaghettifying your actual message handling
If you want to send different kinds of event to make it even easier, then you can 'name' you event by supplying the 'name' field with a value in your json.
Third, if you need to include data with the message, you would supply a value in the 'value' field of your json.
The github page for the standard webchat client has some great information on sending events. It might shed a bit more light on the json.
You can read more about the 'event' activity type here
You message json would look something more like this:
{
"type": "event",
"from": {
"id": "user1"
},
"name": "theEvent",
"value": "someDataMyBotNeeds"
}

Slack RTM API post from a given username

I have integrated the Slack RTM API into my program, and I am able to post to Slack as well as receive new messages from Slack.
The one problem I am having is when posting to Slack, the post comes from my username. I know it is possible to change the posting user in the Web API by setting the "username" and "as_user" field, so I am not sure why this would be any different. Below is my message that I am using. Comment.user.name is a string.
var message =
{
id : 1,
type : "message",
channel : self.channel,
text : comment.text,
thread_ts : self.timestamp,
username : comment.user.name,
as_user : false
};
self.websocket.send(JSON.stringify(message));
Is this possible with the way I am doing it, or is there a better way? Thanks.
It is not possible in the Slack Web API to set a user in that way. There is only one way to achieve this: Obtain an API token for the user you want to post as and use it when making your API request.

Send GCM Push Notification to Multiple Token Id from nodeJs Server [duplicate]

I want to send same message to multiple devices in android using GCM. Currently i am able to send push notification to my device as i am explicitly specifying my registration ID in PHP code. But i want to send it to multiple devices so how can i do this???
Any help or idea are highly appreciated.
Please guide for this
Thanks
What you should do is send multiple registrations Ids (up to 1000 at once) when you send your message to GCM, and you will need to use JSON as your request format.
You can read more about that here:
https://developers.google.com/cloud-messaging/server-ref#downstream
You will need to add your list of Id's to the registration_ids field:
A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs. To send a multicast message, you must use JSON. For sending a single message to a single device, you could use a JSON object with just 1 registration id, or plain text (see below). Required.
Here is an example request from their docs:
Here is a message with a payload and 6 recipients:
{ "data": {
"score": "5x1",
"time": "15:10"
},
"registration_ids": ["4", "8", "15", "16", "23", "42"]
}

Resources