Skip to content

Commit

Permalink
POST requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Pavlovich committed May 15, 2019
1 parent add0f75 commit 7be09a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: go
sudo: false
go:
- 1.9.3
- "1.10"
- 1.12.4
- tip

script:
Expand All @@ -25,4 +24,4 @@ deploy:
on:
tags: true
repo: nikepan/go-rtm2http-slackbot
condition: $TRAVIS_GO_VERSION =~ ^1\.9\.[0-9]+$
condition: $TRAVIS_GO_VERSION =~ ^1\.12\.[0-9]+$
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module go-rtm2http-slackbot

go 1.12

require (
github.com/gorilla/websocket v1.4.0 // indirect
github.com/nlopes/slack v0.5.0
github.com/pkg/errors v0.8.1 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/nlopes/slack v0.5.0 h1:NbIae8Kd0NpqaEI3iUrsuS0KbcEDhzhc939jLW5fNm0=
github.com/nlopes/slack v0.5.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
13 changes: 9 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package main

import (
"encoding/json"
"github.com/nlopes/slack"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"strings"

"github.com/nlopes/slack"
)

type Config struct {
Expand Down Expand Up @@ -77,7 +79,11 @@ Loop:
log.Printf("User: %v; Message: %v\n", userInfo.Profile.Email, ev.Msg.Text) // ev.Msg.User, ev.Msg.Channel

client := &http.Client{}
req, err := http.NewRequest("GET", config.HttpPath+"?user="+ev.Msg.User+"&message="+ev.Msg.Text+"&email="+userInfo.Profile.Email, nil)
parameters := url.Values{}
parameters.Add("user", ev.Msg.User)
parameters.Add("message", ev.Msg.Text)
parameters.Add("email", userInfo.Profile.Email)
req, err := http.NewRequest("POST", config.HttpPath, strings.NewReader(parameters.Encode()))

if config.BasicUser != "" {
req.SetBasicAuth(config.BasicUser, config.BasicPassword)
Expand All @@ -95,8 +101,7 @@ Loop:
log.Printf("HTTP read Error %v\n", err)
} else {
log.Printf("HTTP response: %+v\n", string(body))
params := slack.PostMessageParameters{}
rtm.PostMessage(ev.Msg.Channel, string(body), params)
rtm.SendMessage(rtm.NewOutgoingMessage(string(body), ev.Msg.Channel))
}

case *slack.InvalidAuthEvent:
Expand Down

0 comments on commit 7be09a2

Please sign in to comment.