Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-50853

New Web Services for mod_chat

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.9
    • Fix Version/s: 3.0
    • Component/s: Chat, Web Services
    • Labels:
    • Testing Instructions:
      Hide

      Note: Version number is bumped because new web services are added into the Mobile app service and into the mod_chat list of external functions.

      1. Create inside a course a new Chat activity
      2. Enrol two users in that course as students (student1 and student2)
      3. Log in as the student and visit the url
      4. As admin, enable "Mobile services": Plugins ► Web Services ► Mobile
      5. Create a Token for the student1
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      6. Access to the chat with the student2 user in the Moodle web interface
      7. Next, you can do a CURL REST call simulating a WS client with the student1 user token.
      8. You should try to perform all the requests quickly since there is a timeout and the student1 will be logged off the chat it not recent activity is detected.
        • You need to replace the wstoken, chatid (the chat instance value) and the URL of your moodle instance

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatid=1&wsfunction=mod_chat_login_user&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed

      9. Confirm that
        • The previous call returns a chatsid value (alpha numeric value)
      10. With the student2 write something in the chat in the Web interface
      11. Now, try to retrieve the latest chat messages (you have to use your chatsid value)

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatsid=K4N3l6X1isS1sDWNDt8GHfJ3N8GSkj1x&wsfunction=mod_chat_get_chat_latest_messages&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed

      12. You can append " | python -m "json.tool"" to the command for formatting the output, you will receive and object containing the latest messages and your new timestamp (chatnewlasttime)
      13. Now, to avoid the chat timeout, you can keep the latest curl request running in a shell doing:

        watch "curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatsid=K4N3l6X1isS1sDWNDt8GHfJ3N8GSkj1x&wsfunction=mod_chat_get_chat_latest_messages&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e'"

      14. Now, you can retrieve the list of participants in the chat

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatsid=K4N3l6X1isS1sDWNDt8GHfJ3N8GSkj1x&wsfunction=mod_chat_get_chat_users&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed | python -m "json.tool"

        • Confirm that the user list contains all the users in the chat
      15. Finally, you can send messages

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatsid=K4N3l6X1isS1sDWNDt8GHfJ3N8GSkj1x&messagetext=Testingmessage&wsfunction=mod_chat_send_chat_message&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed | python -m "json.tool"

        • You must confirm that the messages are displayed in the web interface
      Show
      Note: Version number is bumped because new web services are added into the Mobile app service and into the mod_chat list of external functions. Create inside a course a new Chat activity Enrol two users in that course as students (student1 and student2) Log in as the student and visit the url As admin, enable "Mobile services": Plugins ► Web Services ► Mobile Create a Token for the student1 Click on Site administration ► Plugins ► Web services ► Manage tokens Access to the chat with the student2 user in the Moodle web interface Next, you can do a CURL REST call simulating a WS client with the student1 user token. You should try to perform all the requests quickly since there is a timeout and the student1 will be logged off the chat it not recent activity is detected. You need to replace the wstoken, chatid (the chat instance value) and the URL of your moodle instance curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatid=1&wsfunction=mod_chat_login_user&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed Confirm that The previous call returns a chatsid value (alpha numeric value) With the student2 write something in the chat in the Web interface Now, try to retrieve the latest chat messages (you have to use your chatsid value) curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatsid=K4N3l6X1isS1sDWNDt8GHfJ3N8GSkj1x&wsfunction=mod_chat_get_chat_latest_messages&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed You can append " | python -m "json.tool"" to the command for formatting the output, you will receive and object containing the latest messages and your new timestamp (chatnewlasttime) Now, to avoid the chat timeout, you can keep the latest curl request running in a shell doing: watch "curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatsid=K4N3l6X1isS1sDWNDt8GHfJ3N8GSkj1x&wsfunction=mod_chat_get_chat_latest_messages&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e'" Now, you can retrieve the list of participants in the chat curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatsid=K4N3l6X1isS1sDWNDt8GHfJ3N8GSkj1x&wsfunction=mod_chat_get_chat_users&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed | python -m "json.tool" Confirm that the user list contains all the users in the chat Finally, you can send messages curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatsid=K4N3l6X1isS1sDWNDt8GHfJ3N8GSkj1x&messagetext=Testingmessage&wsfunction=mod_chat_send_chat_message&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed | python -m "json.tool" You must confirm that the messages are displayed in the web interface
    • Affected Branches:
      MOODLE_29_STABLE
    • Fixed Branches:
      MOODLE_30_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-50853-master

      Description

      mod_chat_login_user
      Log a user into a chat room in the given chat and return the unique chatsid.

      This function will be a wrapper for core function chat_login_user and it will be used to log a user in a chat root and get the chatsid for starting sending and receiving messages.

      mod_chat_get_chat_users
      Get the list of users in the given chat session.

      This is a wrapper for the chat_get_users function.

      mod_chat_send_chat_message
      Send a message to a chat

      Wrapper function for chat_send_chatmessage

      mod_chat_get_chat_latest_messages
      Retrieve the latest messages starting the given time

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                16/Nov/15