Is there a way to update the status of a message sent from the Slack Web API?
I'm using Slack to build a bot that send Slack messages as SMS using Twilio and I would like to notice the user that the message hasn't been sent if the Twilio call response is an error.
Any suggestions?
I can suggest a blog post by one of my colleagues that walks you through building an SMS Slack bot in Python. You can use it as a guide to translate the setup to Node.js.
The tutorial there shows you how to both send SMS messages to Slack and receive Slack messages via SMS.
Specifically, the following route for receiving Slack messages as SMS:
#app.route('/slack', methods=['POST'])
def slack_post():
if request.form['token'] == SLACK_WEBHOOK_SECRET:
channel = request.form['channel_name']
username = request.form['user_name']
text = request.form['text']
response_message = username " in " channel " says: " text
twilio_client.messages.create(to=USER_NUMBER, from_=TWILIO_NUMBER,
body=response_message)
return Response(), 200
In addition to the code above you could handle any Twilio errors received on a message Status ErrorCode ErrorMessage and notify a user in Slack via the chat.update method.
Related
Am going to integrate DialogFlow Bot with Hangout integration, I need the username and email whom my chatbot is communicating
You will need to set a a direct API from Hangout from there you can use Data.User to grab what you need
You can see more here
https://developers.google.com/resources/api-libraries/documentation/chat/v1/csharp/latest/classGoogle_1_1Apis_1_1HangoutsChat_1_1v1_1_1Data_1_1Message.html
I have the same requirement but I don't really understand the answer provided here.
In Dialogflow I use the native Hangout Chat integration : https://cloud.google.com/dialogflow/docs/integrations/hangouts
So I suspect that this integration does not send all payload from Hangouts chat to Dialogflow.
Have a look at this:
https://developers.google.com/hangouts/chat/reference/message-formats/events
When user sends a message, or adds the bot or does any event, you can get the name and email. For example in Python it would look like this:
#app.route('/', methods=['POST'])
def on_event():
event = request.get_json()
if event['type'] == 'MESSAGE':
response = event['user']['displayName'])
email = event['user']['email'])
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"
}
I have written the code to post to a channel within the workspace on slack for any given channel (assuming it exists), but I keep getting the channel_not_found error on channels that
1.) I can verify that they do indeed exist
2.) The channels are not private as they have the # symbol in front of them and not a lock.
I have triple checked my slack app dashboard and it is installed on the workspace (verified with workspace admins also). I have stored both the OAuth Access Token (begins with xoxp) and the Bot User OAuth Access Token (begins with xoxb) as an environment variable on my machine. I have tried using both within the app and I get the same result with the following permissions/scopes: chat:write:bot, chat:write:user, and bot. I can send messages via webhooks, but am understanding that I need to create a webhook for each and every channel that the app may be posting to. This app needs to be versatile and able to direct message users depending on how they wish to be updated. Any help in finding why the channels cannot be found would greatly be appreciated. In the following code snippet, the post_channel() function is the test function that I am using and simple changing out channel names, etc.
from slackclient import SlackClient
import os
webhook_url = "a webhook url"
def post_message_channel(text, token, channel, is_name):
"""
Creates an api call to post to a message to specific channel (private or
public)and returns the JSON object that is returned by the slack api call.
:param text: The message to post the slack channel.
:param token: The slack app token to identify the sender.
:param title: The title of the message being sent.
:param channel: The channel to post the message to.
:param is_name: If true, then the channel param holds a name, else it holds a channel id
:return: The JSON object that the slack api responds with.
"""
if is_name:
formatted_channel = "#" + channel
else:
formatted_channel = channel
slack_client = SlackClient(token)
output_json = slack_client.api_call(
"chat.postMessage",
channels = formatted_channel,
text = text,
as_user = 1
)
return output_json
def post_channel():
message = "This is a test for posting to a channel"
my_token = os.environ["SLACK_BOT_USER_TOKEN"]
print(post_message_channel(message, my_token, 'file_tracker_test', True))
I have a bot, and I can interact with it. And there's another bot, and I would like my bot to chat with that bot, when they are in the same channel. Is that even possible?
I tried to include a mention like <#IDBOT|name>: text, and even though it appears to me that the mention was successful, the other bot doesn't respond. If I post this mention it will work.
Is there a limitation here?
Yes, it can.
I had the same problem, it turns out that I had included some code that I didn't understand, and that code was preventing the response. I e-mailed slack about it and they set me straight.
The problematic code was this:
if event["type"] == "message" and not "subtype" in event:
user_id, message = parse_direct_mention(event["text"])
if user_id == self_id:
return message, event["channel"]
The helpful response from slack:
The condition below is what's preventing your bot from listening to bot's messages:
if event["type"] == "message" and not "subtype" in event:
When a message is sent by a bot, it will have a subtype, so this means that your logic is disregarding any bot message.
This is helpful because it prevents your bot from responding to its own messages, which would create an infinite loop.
You'll need to modify this condition so that your bot still "ignores" its own messages, but processes messages from other bots. You could do this for instance by looking at the bot ID or user ID and discarding those messages, but not messages from other bots.
In my case, I want the bot to respond to humans always, and bots only if they are trusted, so I did this:
from_user = "subtype" not in event
from_friend_bot = (event["subtype"] == "bot_message") and (event['username'] == f'{ping_source}')
if from_user or from_friend_bot:
user_id, message = parse_direct_mention(event["text"])
if user_id == self_id:
return message, event["channel"]
Yes, bots can talk to each other in a channel.
It depends on how you control the listening bot. I'm using a fork of the official Python Slackbot code (https://github.com/bscan/python-slackbot) and in it, I check for <#U1234567> where U1234567 is the user_id of the bot. When you mention #mybot, Slack replaces #mybot with <#U1234567> in the message. However, when posting as a bot, Slack doesn't replace a callout with the user_id. Instead, a bot can directly put <#U1234567> in the message (and post using as_user=True). Slack will display <#U1234567> as #mybot in the channel and the bot will be able to detect it if looking for that exact message string.
Source: played around until bots talked to each other.
Is it possible to send the location from Telegram to Bot, which made in Bot Framework?
I send my location from my Telegram account to my Bot, but the server does not get them (I don't get the response).
Text messages send normal, and I get response from the server.
Code is very simple:
public async Task<Message> Post([FromBody]Message message)
{
return message.CreateReplyMessage("Tadaa");
}
Dang it, this is a bug. We are filtering out messages without content and we are not treating the location property as "content". To us it looks like no text, no attachments, no channeldata and so no reason to send the message. I will push through a fix.