Send contact form input to Slack with email validation and GeoLite2 information
- Small web service
- Validate email string
- Block bad user-agent requests
- JSON error messages
- Block free email addresses
- Parse GeoLite2 info for Slack message
- Detect browser user-agent and is mobile
- Send Slack message of contact information
URL:
localhost:8080/contact
Name:
Tim Ski
Email:
tim@someemail.com
Message:
Love the site!
Browser:
Chrome
Mobile:
false
Country:
United States
City:
McLean
State:
Virginia
# Binary Build
make build
# Docker Build
make dbuild
## or
# Go build
CGO_ENABLED=0 go build -a -installsuffix cgo -o contactform-slack -ldflags -s -w .
# Create self-signed certs
openssl req -x509 -newkey rsa:4096 -nodes -keyout ./localhost.key -out ./localhost.pem -days 365 -sha256 -subj '/CN=localhost'
# Docker build
sudo docker build . -t perlogix:contactform-slack
./env-file
format
SLACK_URL=https://hooks.slack.com/services/...
REDIRECT_URL=https://somesite.com/contact
GEOLITE_DB=./GeoLite2-City.mmdb
make drun
# or
sudo docker run --name=contactform-slack -d -p 127.0.0.1:8080:8080 --env-file ./env-file --restart always perlogix:contactform-slack
curl -k -XPOST -H 'User-Agent: test-message' -F 'email=tim@someemail.com' -F 'name=tim ski' -F 'message=whats up' https://localhost:8080/contact
Responses
{"error":"Email not valid"}
{"error":"Missing form information"}