I am using Python and it's Slacker API to post messages to a slack channel and it's posting the messages nicely.
Now what I want to do is create a button that says, More Info and when it's clicked, I want to show a list of items.
But when the button is clicked, slackbot says oh no, something weng wrong, Please try that again
Here is an example: link
Below is my json and the code
msg = "<!here> Hello guys! "
moreInfo = ['person', 'person2', 'person3']
message = [{
"title": "Lunch time has been decided",
"text": "You will also be joining",
"actions": [
{
"name": "buttonName",
"text": "More Info",
"type": "button",
"value": moreInfo
}]
}]
slack.chat.post_message('#teamChannel', msg, username='my_username', attachments=message)
And this is the what it looks like in Slack when I click on More info button.
Any help is appreciated! Thanks :)
Do you have a button endpoint setup already? If not, you will see that error message.
Or if you made the same mistake I did, you are using the incorrect token. This is non-obvious from the Slack docs. You can post a message with a custom integration bot token, including using attachments (i.e. interactive buttons). However, if you want to actually respond to a button press, you need to post the message with a full-fledged Slack app token (even if you don't intend on releasing your app into the wild). That means creating an endpoint for your oauth2 flow to add your app to a Slack team, and acquiring your bot token there.
Create a Slack app if you haven't already.
Create an oauth GET endpoint (e.g. /slack/authorize)
Set your Slack app's "Redirect URI" to your auth endpoint
Your endpoint should expect a code in its query parameters. Call the Slack API oauth.access with your app's client_id, client_secret, and that code to exchange for aforementioned app token. To post your interactive message from a bot, you will need the bot token (prefixed "xoxo-").
Related
Working on a script to present data in Slack channel.. I have a script I'm working on to request and return data that I need to post in the channel that gets invoked with a Slash command, but having an issue with presenting the data in the slack channel from where I've executed the Slash command. I've been attempting to work with the Block Kit Builder, but I see no way of presenting that data coming back from my script using the template I created.
Then in the Block kit builder, I can kind of see the format I want and send it to Slack from the Block kit builder, but if I wanted my return response from my Python script to be formatted by the template and respond in the channel, it doesn't seem to work.. I'm thinking I'm definitely doing something wrong, but was looking for suggestions..
I've been searching on possibly how to do it in Flask, which is what I'm using to execute a Slash command in Slack to invoke my Python script to query the API, get the response and send it to Slack..
Thanx.
P.S. Stackflow won't allow me to post a snippet of the json and/or images.. yet... something about a '10 reputation'...
I was able to figure this out. In my code, I reflected this:
for i in pdjson:
t = {}
try:
t["text"] = {
"type": "plain_text",
"text": f'{i["escalation_policy"]["summary"]} - Layer: {i["escalation_level"]}'
}
except (KeyError):
t["text"] = {
"type": "plain_text",
"text": f'{i["escalation_policy"]["summary"]} - Layer: {i["escalation_level"]}'
}
t["value"] = i["user"]["summary"]
Now I can present in the slack workspace with the block kit template. Now I just have to figure out how make the 'value' show up once I select an item in the list.
I am trying to create a Discord webhook, with the avatar and username assigned inside the code.
This is the code I have so far. I have no idea what comes before or after this.
{
"username": "Webhook",
"avatar_url": "https://i.imgur.com/4M34hi2.png",
"content": "Text message. Up to 2000 characters.",
}
Can you instead create the webhook from Discord's GUI (see "Making A Webhook" section)?
If you need to do it programmatically, can you confirm you're sending a POST request to /channels/{channel.id}/webhooks and have the MANAGE_WEBHOOKS role, per the webhook resource? That doc also only shows name and avatar as fields for a create webhook request.
I want my facebook chatbot to send multiple responses at the same time.
For example:
When the user says:
Hey
The chatbot should respond with:
Hey!
How are you?
Currently using dialogflow and a webhook built using python to build responses.
It is possible. But not in a way I consider clean.
You can add a response under the 'default' tab.
Under the 'facebook' tab you can than tick Use response from the DEFAULT tab as the first response.. This way two responses are send to facebook and to facebook only.
But you can send messages to the messenger via the facebook send api from your webhook at any time. Have a look at: https://developers.facebook.com/docs/messenger-platform/reference/send-api
This has nothing to do with dialogflow though.
You can find the id of the facebook user in the payload, dialogflow send to your webhook.
Here is an example of where you can find it.
{:originalDetectIntentRequest
{:payload
{:source "facebook",
:data
{:recipient {:id "1144092719067446"},
:sender {:id "1235572976569567"}, <== This is the id you are looking for!
:timestamp 1.536065422409E12,
:message
{:mid
"YzKAMwoJlAR0n3Vke2RJf83aVMGWzBnJ77SfUDe_NwkzIT1BBQXaWPVjN6Qf0xN4veairdW504PoKzcKV3lKBw",
:seq 183071.0,
:text "They are loyal"}}},
:source "facebook"},
...
...}
I'm setting up a slackbot with slash commands and according to API you're able to pass username to set the username of a bot. When I try it, the name does not update. Does this not work with slash commands in the same way that it does with bots?
from bottle import run, post, request
#post('/hello')
def hello():
mydict = request.forms.get('text')
response = {
"username": "test",
"response_type": "in_channel",
"text": "Greetings!"
}
return response
matt [11:00 AM]
/hello
MyBot APP [11:00 AM]
Greetings!
Correct. You can not change the name of the app that appears on Slack when you respond to a request like that. It will always show the name you configured in the app settings.
However, there is a workaround for your use case: Instead of replying to the received request directly you can send a message into the channel / to the user with chat.postMessage, which will allow you to specify a custom username and icon.
I'm trying to share a card ( the html inside it ) from my Glassware using python and the Python Mirror API Quickstart code.
creds = StorageByKeyName(Credentials, '#####', 'credentials').get()
plus_service = util.create_service('plus', 'v1', creds)
moment = {"type":"http://schemas.google.com/AddActivity",
"target": {
"id": "target-id-1",
"type":"http://schemas.google.com/AddActivity",
"name": "The Google+ Platform",
"description": "A page that describes just how awesome Google+ is!",
"image": "https://developers.google.com/+/plugins/snippet/examples/thing.png"
}
}
google_request = plus_service.moments().insert(userId='me', collection='vault', body=moment)
result = google_request.execute()
I got this response back:
HttpError: <HttpError 403 when requesting https://www.googleapis.com/plus/v1/people/me/moments/vault?alt=json returned "Insufficient Permission">
I can understand that is a permission problem but my question is, what is the suggested UI to ask to a glass user for G+ permissions?
Furthermore, by adding "https://www.googleapis.com/auth/plus.login" in the requested permissions I got this:
https://www.googleapis.com/plus/v1/people/me/moments/vault?alt=json returned "Unauthorized">
Thanks in advance
To get G+ access, you can piggyback on the authorization process that Mirror API uses. Make the following modifications to the Mirror API Python Quickstart project:
First, enable the Google+ API in the Google API Console for your project.
Second, in oauth/hander.py, add your G+ scope to the SCOPES list:
SCOPES = ('https://www.googleapis.com/auth/glass.timeline '
'https://www.googleapis.com/auth/glass.location '
'https://www.googleapis.com/auth/userinfo.profile '
'https://www.googleapis.com/auth/plus.login')
Third, revoke your old auth tokens and get fresh ones. Do this by signing out of and signing back into your Quickstart instance's web front end. When you sign in, the sign in page should be updated to list the new Google+ permission:
With these steps, the code you posted should work. Comment if it doesn't and I can help you continue debugging.