jail: sendMessage and showSuggestions handlers (#195)
Merging what's already implemented in bugs/whisper-on-geth.1.6.1
This commit is contained in:
parent
b50c46caa8
commit
444a2d93b7
|
@ -6,10 +6,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// EventLocalStorageSet is triggered when set request is sent to local storage
|
||||
EventLocalStorageSet = "local_storage.set"
|
||||
|
||||
// LocalStorageMaxDataLen is maximum length of data that you can store in local storage
|
||||
EventSendMessage = "jail.send_message"
|
||||
EventShowSuggestions = "jail.show_suggestions"
|
||||
LocalStorageMaxDataLen = 256
|
||||
)
|
||||
|
||||
|
@ -107,3 +106,47 @@ func makeLocalStorageSetHandler(chatID string) func(call otto.FunctionCall) (res
|
|||
return newResultResponse(call, true)
|
||||
}
|
||||
}
|
||||
|
||||
// SendMessageEvent wraps Jail send signals
|
||||
type SendMessageEvent struct {
|
||||
ChatID string `json:"chat_id"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func makeSendMessageHandler(chatID string) func(call otto.FunctionCall) (response otto.Value) {
|
||||
return func(call otto.FunctionCall) otto.Value {
|
||||
message := call.Argument(0).String()
|
||||
|
||||
node.SendSignal(node.SignalEnvelope{
|
||||
Type: EventSendMessage,
|
||||
Event: SendMessageEvent{
|
||||
ChatID: chatID,
|
||||
Message: message,
|
||||
},
|
||||
})
|
||||
|
||||
return newResultResponse(call, true)
|
||||
}
|
||||
}
|
||||
|
||||
// ShowSuggestionsEvent wraps Jail show suggestion signals
|
||||
type ShowSuggestionsEvent struct {
|
||||
ChatID string `json:"chat_id"`
|
||||
Markup string `json:"markup"`
|
||||
}
|
||||
|
||||
func makeShowSuggestionsHandler(chatID string) func(call otto.FunctionCall) (response otto.Value) {
|
||||
return func(call otto.FunctionCall) otto.Value {
|
||||
suggestionsMarkup := call.Argument(0).String()
|
||||
|
||||
node.SendSignal(node.SignalEnvelope{
|
||||
Type: EventShowSuggestions,
|
||||
Event: ShowSuggestionsEvent{
|
||||
ChatID: chatID,
|
||||
Markup: suggestionsMarkup,
|
||||
},
|
||||
})
|
||||
|
||||
return newResultResponse(call, true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,6 +182,12 @@ func (jail *Jail) Parse(chatID string, js string) string {
|
|||
return makeError(err.Error())
|
||||
}
|
||||
|
||||
// sendMessage/showSuggestions handlers
|
||||
vm.Set("statusSignals", struct{}{})
|
||||
statusSignals, _ := vm.Get("statusSignals")
|
||||
statusSignals.Object().Set("sendMessage", makeSendMessageHandler(chatID))
|
||||
statusSignals.Object().Set("showSuggestions", makeShowSuggestionsHandler(chatID))
|
||||
|
||||
jjs := string(web3JSCode) + `
|
||||
var Web3 = require('web3');
|
||||
var web3 = new Web3(jeth);
|
||||
|
|
Loading…
Reference in New Issue