slack
slack copied to clipboard
initial documentation for events example
This is a Documentation PR
As a new user of slack-go who inherited a slackbot, I found the examples/eventsapi/events.go
example difficult to get working. This README file will help others avoid the same fate. Could I have posted this as a question in Stackoverflow? Yes. But as a new user I wouldn't have known what to search for. And anyway, it is best to get answers from the source.
@mhemken-nyt Hi, I fixed this PR in documentation/events-example branch. Could you add these fixes in this PR?
git diff
diff --git a/examples/eventsapi/README.md b/examples/eventsapi/README.md
index 9b4e27d..af8b701 100644
--- a/examples/eventsapi/README.md
+++ b/examples/eventsapi/README.md
@@ -1,39 +1,3 @@
# Events Example
The following are the settings you'll need to configure in the Slack UI to get this example to work. In particular, you must disable socket mode to reveal the `reqeust_url` text field in the Slack UI.
-
-```
-_metadata:
- major_version: 1
- minor_version: 1
-display_information:
- name: Name
- description: Description
- background_color: "<hexcode>"
-features:
- app_home:
- home_tab_enabled: N/A
- messages_tab_enabled: N/A
- messages_tab_read_only_enabled: N/A
- bot_user:
- display_name: Name
- always_online: N/A
-oauth_config:
- scopes:
- bot:
- - app_mentions:read
- - channels:history
-settings:
- allowed_ip_address_ranges: # <--- Required
- - xxx.xxx.xxx.xxx/32
- - xxx.xxx.xxx.xxx/32
- - xxx.xxx.xxx.xxx/32
- event_subscriptions:
- request_url: https://example.com/example-endpoint
- bot_events:
- - app_mention
- - message.channels
- org_deploy_enabled: N/A
- socket_mode_enabled: false # <--- Required
-
-```
diff --git a/examples/eventsapi/events.go b/examples/eventsapi/events.go
index 25049ad..e3bcb50 100644
--- a/examples/eventsapi/events.go
+++ b/examples/eventsapi/events.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
...skipping...
)
// You more than likely want your "Bot User OAuth Access Token" which starts with "xoxb-"
-var api = slack.New("TOKEN")
+var api = slack.New(os.Getenv("SLACK_TOKEN"))
func main() {
signingSecret := os.Getenv("SLACK_SIGNING_SECRET")
@@ -56,7 +57,10 @@ func main() {
innerEvent := eventsAPIEvent.InnerEvent
switch ev := innerEvent.Data.(type) {
case *slackevents.AppMentionEvent:
- api.PostMessage(ev.Channel, slack.MsgOptionText("Yes, hello.", false))
+ _, _, err := api.PostMessage(ev.Channel, slack.MsgOptionText("Yes, hello.", false))
+ if err != nil {
+ log.Println(err)
+ }
}
}
})
diff --git a/examples/eventsapi/manifest.yaml b/examples/eventsapi/manifest.yaml
new file mode 100644
index 0000000..3e6df31
--- /dev/null
+++ b/examples/eventsapi/manifest.yaml
@@ -0,0 +1,25 @@
+_metadata:
+ major_version: 1
+ minor_version: 1
+display_information:
+ name: Name
+ description: Description
+ background_color: "<hexcode>"
+features:
+ bot_user:
+ display_name: Name
+ always_online: false
+oauth_config:
+ scopes:
+ bot:
+ - app_mentions:read
+ - chat:write
+ - channels:history
+settings:
+ event_subscriptions:
+ request_url: https://example.com/events-endpoint
+ bot_events:
+ - app_mention
+ - message.channels
+ org_deploy_enabled: false
+ socket_mode_enabled: false
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.
This PR was closed because it has been stalled for 10 days with no activity.