Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing indicator is missing #40

Closed
Shaked opened this issue Feb 4, 2017 · 4 comments
Closed

Typing indicator is missing #40

Shaked opened this issue Feb 4, 2017 · 4 comments

Comments

@Shaked
Copy link
Contributor

Shaked commented Feb 4, 2017

Hey,

I hope I am just missing something, but it seems that it is impossible to send a typing indicator without having a Message object.

The whole idea of the typing indicator is to show the user that something is happening while the message is being generated. This feature might be valuable before a message is going to be sent, e.g when the backend of the bot is doing some processing but wants to show the user that something is happening and they should wait.

What do you think?

Thank you
Shaked

@Shaked
Copy link
Contributor Author

Shaked commented Feb 4, 2017

I was thinking about something like:

Messenger.php

     /**
+     * @param $recipient
+     * @param NotificationType $notificationType
+     */
+    public function setTypingStatus($recipient, $typingIndicator) {
+        $options = RequestOptionsFactory::createForTyping($recipient, $typingIndicator);
+        $this->client->send('POST', '/me/messages', null, [], [], $options);
+    }
+

and then

+class RequestOptionsFactory {
+
+    /**
+     * @param $recipientOrPhone
+     * @param $typingIndicator
+     * @return mixed
+     */
+    public static function createForTyping($recipientOrPhone, $typingIndicator) {
+        $options = [];
+        $data = [
+            'recipient'     => self::createRecipientField($recipientOrPhone),
+            'sender_action' => $typingIndicator,
+        ];
+        $options[RequestOptions::JSON] = $data;
+
+        return $options;
+    }
+

And of course...

+<?php
+
+namespace Tgallice\FBMessenger;
+
+interface TypingIndicator {
+
+    /**
+     * Mark last message as read
+     */
+    const MARK_SEEN = 'mark_seen';
+
+    /**
+     * Turn typing indicators on
+     */
+    const TYPING_ON = 'typing_on';
+
+    /**
+     * Turn typing indicators off
+     */
+    const TYPING_OFF = 'typing_off';
+
+}

Feel free to comment and if it's ok I will send a pull request.

Shaked

@tgallice
Copy link
Owner

Hello @Shaked ! You absolutely right, this feature is missing and need to be added :) I like your idea ! If you have already implement something feel free to open a PR or I will handle it.

Thanks

@Shaked
Copy link
Contributor Author

Shaked commented Feb 12, 2017

@tgallice - Actually I have. I will send a pull request ASAP.

Thank you!

@tgallice
Copy link
Owner

Thank @Shaked ! I have merge your PR, we can close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants