Skip to content

Commit

Permalink
added post method for posting chat message with json request
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jun 21, 2015
1 parent 2ac738f commit e116657
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions grails-app/controllers/net/zomis/duga/BotController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.zomis.duga

import grails.transaction.Transactional
import net.zomis.duga.chat.WebhookParameters
import org.grails.web.json.JSONObject
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.core.env.Environment

Expand All @@ -15,6 +16,39 @@ class BotController {
@Autowired
Environment environment

@Transactional(readOnly = true)
def jsonPost() {
println 'json post'
JSONObject json = request.JSON
println json
println request
println params

String text = json.text
header 'Access-Control-Allow-Origin', '*'
if (!text) {
render 'No text found'
return
}
String roomId = json.roomId
WebhookParameters roomParams = WebhookParameters.toRoom(roomId)

User user = User.findByApiKey(json.apiKey)
if (user) {
for (Authority auth : user.authorities) {
if (auth.authority == 'ROLE_ADMIN') {
println 'Request Text: ' + text
bot.postSingle(roomParams, text)
def result = render 'OK'
return result
}
}
render 'Unauthorized'
} else {
render 'User not found'
}
}

@Transactional(readOnly = true)
def post() {
println 'post'
Expand Down

0 comments on commit e116657

Please sign in to comment.