Status-react: Allow to send a chat message from an extension

Created on 28 Jan 2019  Â·  32Comments  Â·  Source: status-im/status-react

User Story

As a developer, I want to be able to send a chat message (private chat, public channel) from an extension event.

Description

Type: Feature

bounty-s extensions

Most helpful comment

@krisc if you need some help i cant give you some. we could have a chat and you can explain me the block you have...

All 32 comments

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


__This issue now has a funding of 80.0 DAI (80.0 USD @ $1.0/DAI) attached to it.__

Can't we already do this with chat.command/send-message?

No it's specific to chat command message.

Oh I see. So would this be a new event itself? Maybe you could give an example of how this would look like?

Right a new event would be perfect.
A potential syntax could be:

[chat/send-message {:to "channel-or-address" :value "Hello!!"}]

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


__Work has been started__.

These users each claimed they can complete the work by 10 months, 2 weeks from now.
Please review their action plans below:

1) krisc has been approved to start work.

I will create a new event chat/send-message that will allow to send chat messages from an extension. I believe I will be able to use commands-sending/send to accomplish this, but I would like clarification from the developers.

Learn more on the Gitcoin Issue Details page.

@StatusSceptre Can I can approved to work on this soon? I have a lot of time this week for this.

approved!

@jeluard can you confirm that I can use commands-sending/send to accomplish this?

@krisc No, commands-sending/send is specific to sending commands. Here the goal is to send a regular string message to any chat, identified by an address or a channel name.

@jeluard Okay I explored the code some more and it looks like I could use the function send-message in chat.models.message. Is this correct?

Also, how exactly do I create a new event? Inside the def capacities in extensions/core.cljs I added this:

'chat/send-message
                {:permissions [:read]
                 :value       :chat/send-message
                 :arguments   {:value :string}} 

Then I added these two in extensions.core.cljs:

(re-frame/reg-fx
 ::chat/send-message
 (fn [value]
   (log/debug "inside re-frame/reg-fx::chat/send-message")
   (log/debug "value = " value)))

(handlers/register-handler-fx
 :chat/send-message
 (fn [_ [_ _ {:keys [value]}]]
   (log/debug "inside handlers/register-handler-fx:chat/send-message")
   (log/debug "value = " value)))

On compilation, I get this error:

53   ::chat/send-message
       /home/kris/status-react/src/status_im/extensions/core.cljs [line 53, col 21] Invalid keyword: ::chat/send-message.

Is there somewhere else in the code to add this as a new keyword?

@krisc Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] reminder (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Yes, I'm still working on this.

@jeluard about my last question, I think I'm getting an error because the new keyword wasn't added to the spec, right? I'm not sure where the specs for these extension events are located. If you can direct me to where that is in the code, I can continue with this issue.

::chat/send-message is not a valid keyword according to clojure syntax. Leading double semi colon can only be used in specific contexts

Okay, got it. Still having trouble with the extension installer recognizing the new event. Getting unknown-reference error.

Oops, nevermind just had a typo :/

hello @krisc join @tbenr who has had extensive experience building extensions, myself (wannabe contributor), and core-devs in Status - share your experience, teach, learn and grow

there's

http://get.status.im/chat/public/clojure for Clojure talk
http://get.status.im/chat/public/status-core-devs and
http://get.status.im/chat/public/status-core where core devs / contributors hang out

there's also
http://get.status.im/chat/ethdenver-extensions for extensions hacking at upcoming Ethdenver

@krisc Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] reminder (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@gitcoinbot I'll get back to this after the weekend

@krisc Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

  • [x] reminder (3 days)
  • [ ] escalation to mods (6 days)

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

@gitcoinbot I hit a road block so I was working on other issues to take a break from this, but I'll was planning on taking another look later today.

@krisc if you need some help i cant give you some. we could have a chat and you can explain me the block you have...

@tbenr are you part of the status dev team?

I'm defining a new event in extensions/core.cljs. It looks something like this:

(re-frame/reg-event-fx
 :chat/send-message
  (fn [cofx [_ message-text]]
   (chat.input/send-plain-text-message-fx cofx "chat message!" "0xSomeHardCodedChatAddressForNow")))

My problem is that the call to chat.input/send-plain-text-message-fx passes in cofx, but somewhere down the line the :now field becomes nil and that causes an error when I use an extension which uses this event.

So I'm figuring out how to pass in cofx to chat.input/send-plain-text-message-fx with the correct timestamp.

@krisc no but i'm contributing in extensions :)

becomes nil or is never set to current timestamp?

btw maybe something like:

(re-frame/reg-event-fx
 :chat/send-message
  (fn [cofx [_ message-text]]
    (fx/merge cofx
      {:now []}
      (chat.input/send-plain-text-message-fx "chat message!" "0xSomeHardCodedChatAddressForNow")))

(using :now fx from ns status-im.utils.datetime)

@tbenr thanks! exactly what I was looking for :)

@tbenr Actually, it was datatime/timestamp that I needed. But thanks for pointing me in the right direction nontheless!

Also fx/merge didn't like the 3rd parameter (I believe they all have to be maps. So I ended up writing it this way:

(re-frame/reg-event-fx
 :chat/send-message
  (fn [cofx [_ message-text arguments]]
   (log/debug "arguments = " arguments)
   (chat.input/send-plain-text-message-fx (assoc cofx :now (datetime/timestamp))"chat message!" "0xSomeHardCodedChatAddressForNow")))

And this works!

now, the next step is to try to parameterize this with a custom "chat message" and not a hardcoded address. I was able to call this event from an extension like this:

[chat/send-message {:to "0x04825abbccf20caa211e1564dc566222278f3f08a5d0013f9277d643a8e10e52e48486248d432a31ce3832ce7eb51d44a62503e54f8088595310b28c0a2a3016c3" :value  "Chat Message"}]

In the log message above, I could see the :value but not :to.

@krisc how you defined chat/send-message event? (capacities in _extensions/core.cljs_)

@tbenr Oh totally forgot about this definition here. Thanks for reminding me! I had it like this:

'chat/send-message
                {:permissions [:read]
                 :value       :chat/send-message
                 :arguments   {:value :string}} 

seems so obvious haha

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


__Work for 80.0 DAI (80.0 USD @ $1.0/DAI) has been submitted by__:

  1. @krisc

@StatusSceptre please take a look at the submitted work:

  • PR by @krisc

@StatusSceptre made a new PR for this https://github.com/status-im/status-react/pull/7694

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


__The funding of 80.0 DAI (80.0 USD @ $1.0/DAI) attached to this issue has been approved & issued to @krisc.__

Was this page helpful?
0 / 5 - 0 ratings