mirror of
https://github.com/status-im/status-react.git
synced 2025-02-23 16:18:32 +00:00
text-message in command handler
to and from props in context in suggestions function ability to send request using text-message property in handler and via status.sendMessage show request's text if it exists
This commit is contained in:
parent
33d7146b25
commit
4f6ebb53d3
@ -71,13 +71,12 @@ function demoSuggestions(params, context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {markup: view};
|
return {markup: view};
|
||||||
};
|
}
|
||||||
|
|
||||||
status.addListener("on-message-input-change", demoSuggestions);
|
status.addListener("on-message-input-change", demoSuggestions);
|
||||||
status.addListener("init", demoSuggestions);
|
|
||||||
status.addListener("on-message-send", function (params, context) {
|
status.addListener("on-message-send", function (params, context) {
|
||||||
var cnt = localStorage.getItem("cnt");
|
var cnt = localStorage.getItem("cnt");
|
||||||
if(!cnt) {
|
if (!cnt) {
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,3 +106,41 @@ status.addListener("on-message-send", function (params, context) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
status.command({
|
||||||
|
name: "init-request",
|
||||||
|
description: "send-request",
|
||||||
|
color: "#a187d5",
|
||||||
|
sequentialParams: true,
|
||||||
|
params: [{
|
||||||
|
name: "address",
|
||||||
|
type: status.types.TEXT,
|
||||||
|
placeholder: "address"
|
||||||
|
}],
|
||||||
|
handler: function (params) {
|
||||||
|
return {
|
||||||
|
"text-message": {
|
||||||
|
type: "request",
|
||||||
|
content: {
|
||||||
|
command: "response",
|
||||||
|
params: {first: "123"},
|
||||||
|
text: "That's request's content! It works!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
status.response({
|
||||||
|
name: "response",
|
||||||
|
color: "#a187d5",
|
||||||
|
sequentialParams: true,
|
||||||
|
params: [{
|
||||||
|
name: "first",
|
||||||
|
type: status.types.TEXT,
|
||||||
|
placeholder: "first"
|
||||||
|
}],
|
||||||
|
handler: function (params) {
|
||||||
|
return {"text-message": "ok"};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@ -242,8 +242,11 @@ var status = {
|
|||||||
updateDb: function (db) {
|
updateDb: function (db) {
|
||||||
addContext("update-db", db)
|
addContext("update-db", db)
|
||||||
},
|
},
|
||||||
sendMessage: function (text) {
|
sendMessage: function (message) {
|
||||||
statusSignals.sendMessage(text);
|
if(typeof message !== "string") {
|
||||||
|
message = JSON.stringify(message);
|
||||||
|
}
|
||||||
|
statusSignals.sendMessage(message);
|
||||||
},
|
},
|
||||||
addLogMessage: function (type, message) {
|
addLogMessage: function (type, message) {
|
||||||
var message = {
|
var message = {
|
||||||
|
@ -115,7 +115,8 @@
|
|||||||
(handlers/register-handler
|
(handlers/register-handler
|
||||||
:load-chat-parameter-box
|
:load-chat-parameter-box
|
||||||
(handlers/side-effect!
|
(handlers/side-effect!
|
||||||
(fn [{:keys [current-chat-id] :as db} [_ {:keys [name type bot] :as command}]]
|
(fn [{:keys [current-chat-id current-account-id] :as db}
|
||||||
|
[_ {:keys [name type bot] :as command}]]
|
||||||
(let [parameter-index (input-model/argument-position db current-chat-id)]
|
(let [parameter-index (input-model/argument-position db current-chat-id)]
|
||||||
(when (and command (> parameter-index -1))
|
(when (and command (> parameter-index -1))
|
||||||
(let [jail-id (or bot current-chat-id)
|
(let [jail-id (or bot current-chat-id)
|
||||||
@ -128,8 +129,12 @@
|
|||||||
args (-> (get-in db [:chats current-chat-id :input-text])
|
args (-> (get-in db [:chats current-chat-id :input-text])
|
||||||
(input-model/split-command-args)
|
(input-model/split-command-args)
|
||||||
(rest))
|
(rest))
|
||||||
|
to (get-in db [:contacts current-chat-id :address])
|
||||||
|
from (get-in db [])
|
||||||
params {:parameters {:args args}
|
params {:parameters {:args args}
|
||||||
:context (merge {:data data}
|
:context (merge {:data data
|
||||||
|
:from current-account-id
|
||||||
|
:to to}
|
||||||
(input-model/command-dependent-context-params command))}]
|
(input-model/command-dependent-context-params command))}]
|
||||||
(status/call-jail
|
(status/call-jail
|
||||||
{:jail-id jail-id
|
{:jail-id jail-id
|
||||||
|
@ -70,16 +70,17 @@
|
|||||||
(register-handler :prepare-command!
|
(register-handler :prepare-command!
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [current-public-key network-status] :as db}
|
(fn [{:keys [current-public-key network-status] :as db}
|
||||||
[_ add-to-chat-id {:keys [chat-id command-message command handler-data] :as params}]]
|
[_ add-to-chat-id {:keys [chat-id command-message command] :as params}]]
|
||||||
(let [clock-value (messages/get-last-clock-value chat-id)
|
(let [clock-value (messages/get-last-clock-value chat-id)
|
||||||
request (:request (:handler-data command))
|
request (:request (:handler-data command))
|
||||||
|
handler-data (:handler-data command)
|
||||||
hidden-params (->> (:params (:command command))
|
hidden-params (->> (:params (:command command))
|
||||||
(filter #(= (:hidden %) true))
|
(filter #(= (:hidden %) true))
|
||||||
(map :name))
|
(map :name))
|
||||||
command' (->> (assoc command-message :handler-data handler-data)
|
command' (->> (assoc command-message :handler-data handler-data)
|
||||||
(prepare-command current-public-key chat-id clock-value request)
|
(prepare-command current-public-key chat-id clock-value request)
|
||||||
(cu/check-author-direction db chat-id))]
|
(cu/check-author-direction db chat-id))]
|
||||||
(log/debug "Handler data: " request handler-data (dissoc params :commands :command-message))
|
(log/debug "Handler data: " request (:handler-data command) (dissoc params :commands :command-message))
|
||||||
(dispatch [:update-message-overhead! chat-id network-status])
|
(dispatch [:update-message-overhead! chat-id network-status])
|
||||||
(dispatch [:set-chat-ui-props {:sending-in-progress? false}])
|
(dispatch [:set-chat-ui-props {:sending-in-progress? false}])
|
||||||
(dispatch [::send-command! add-to-chat-id (assoc params :command command') hidden-params])
|
(dispatch [::send-command! add-to-chat-id (assoc params :command command') hidden-params])
|
||||||
@ -238,17 +239,29 @@
|
|||||||
:from chat-id
|
:from chat-id
|
||||||
:to "me"}]))))))
|
:to "me"}]))))))
|
||||||
|
|
||||||
(register-handler :send-message-from-jail
|
(defn handle-message-from-bot [{:keys [message chat-id]}]
|
||||||
(u/side-effect!
|
(cond
|
||||||
(fn [_ [_ {:keys [chat_id message]}]]
|
(string? message)
|
||||||
(dispatch [:received-message
|
(dispatch [:received-message
|
||||||
{:message-id (random/id)
|
{:message-id (random/id)
|
||||||
:content (str message)
|
:content (str message)
|
||||||
:content-type text-content-type
|
:content-type text-content-type
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:chat-id chat_id
|
:chat-id chat-id
|
||||||
:from chat_id
|
:from chat-id
|
||||||
:to "me"}]))))
|
:to "me"}])
|
||||||
|
|
||||||
|
(= "request" (:type message))
|
||||||
|
(dispatch [:add-request-message!
|
||||||
|
{:content (:content message)
|
||||||
|
:chat-id chat-id}])))
|
||||||
|
|
||||||
|
(register-handler :send-message-from-jail
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ {:keys [chat_id message]}]]
|
||||||
|
(let [parsed-message (types/json->clj message)]
|
||||||
|
(handle-message-from-bot {:message parsed-message
|
||||||
|
:chat-id chat_id})))))
|
||||||
|
|
||||||
(register-handler :show-suggestions-from-jail
|
(register-handler :show-suggestions-from-jail
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
@ -301,7 +314,10 @@
|
|||||||
current-account-id accounts contacts] :as db}
|
current-account-id accounts contacts] :as db}
|
||||||
[_ {:keys [chat-id command]}]]
|
[_ {:keys [chat-id command]}]]
|
||||||
(log/debug "sending command: " command)
|
(log/debug "sending command: " command)
|
||||||
(when (not (get-in contacts [chat-id :dapp?]))
|
(if (get-in contacts [chat-id :dapp?])
|
||||||
|
(when-let [text-message (get-in command [:content :handler-data :text-message])]
|
||||||
|
(handle-message-from-bot {:message text-message
|
||||||
|
:chat-id chat-id}))
|
||||||
(let [{:keys [public-key private-key]} (chats chat-id)
|
(let [{:keys [public-key private-key]} (chats chat-id)
|
||||||
{:keys [group-chat public?]} (get-in db [:chats chat-id])
|
{:keys [group-chat public?]} (get-in db [:chats chat-id])
|
||||||
|
|
||||||
@ -332,3 +348,15 @@
|
|||||||
:else
|
:else
|
||||||
(protocol/send-message! (assoc-in options
|
(protocol/send-message! (assoc-in options
|
||||||
[:message :to] chat-id))))))))
|
[:message :to] chat-id))))))))
|
||||||
|
|
||||||
|
(register-handler :add-request-message!
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ {:keys [content chat-id]}]]
|
||||||
|
(dispatch [:received-message
|
||||||
|
{:message-id (random/id)
|
||||||
|
:content (assoc content :bot chat-id)
|
||||||
|
:content-type content-type-command-request
|
||||||
|
:outgoing false
|
||||||
|
:chat-id chat-id
|
||||||
|
:from chat-id
|
||||||
|
:to "me"}]))))
|
||||||
|
@ -78,6 +78,7 @@
|
|||||||
(fn [{:keys [message-id content from incoming-group]}]
|
(fn [{:keys [message-id content from incoming-group]}]
|
||||||
(let [commands @commands-atom
|
(let [commands @commands-atom
|
||||||
params (:params content)
|
params (:params content)
|
||||||
|
text-content (:text content)
|
||||||
{:keys [command content]} (parse-command-request commands content)
|
{:keys [command content]} (parse-command-request commands content)
|
||||||
command (if (and params command)
|
command (if (and params command)
|
||||||
(merge command {:prefill (vals params)})
|
(merge command {:prefill (vals params)})
|
||||||
@ -92,7 +93,7 @@
|
|||||||
[view @markup]
|
[view @markup]
|
||||||
[text {:style st/style-message-text
|
[text {:style st/style-message-text
|
||||||
:font :default}
|
:font :default}
|
||||||
(or @markup content)])]]
|
(or text-content @markup content)])]]
|
||||||
(when (:request-text command)
|
(when (:request-text command)
|
||||||
[view st/command-request-text-view
|
[view st/command-request-text-view
|
||||||
[text {:style st/style-sub-text
|
[text {:style st/style-sub-text
|
||||||
|
@ -13,4 +13,6 @@
|
|||||||
|
|
||||||
(defn json->clj [json]
|
(defn json->clj [json]
|
||||||
(when-not (= json "undefined")
|
(when-not (= json "undefined")
|
||||||
(js->clj (.parse js/JSON json) :keywordize-keys true)))
|
(try
|
||||||
|
(js->clj (.parse js/JSON json) :keywordize-keys true)
|
||||||
|
(catch js/Error _ (when (string? json) json)))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user