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

New Web Services for retrieving chat sessions

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.5
    • 3.2, 3.5
    • Chat
    • MOODLE_32_STABLE, MOODLE_35_STABLE
    • MOODLE_35_STABLE
    • MDL-57394-master
    • Hide
      1. As admin go to Site administration > Plugins > Activity modules > Chat and check that the "Chat method" field is set to "Ajax method"
      2. As teacher create a chat activity with "Everyone can view past sessions" set to "Yes"
      3. As student enrolled in the course where is the chat access to the chat, write one message, note the 'id' in the popup URL (you will need it later) and close the chat popup window
      4. As admin, enable "Enable web services for mobile devices", you can find the option in Site administration ► Mobile app ► Mobile settings
      5. Create a Token in the mobile app service for the student:
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      6. Next, in the command line interface, you can do a CURL REST call simulating a WS client with the user.
        • You need to replace the wstoken value (for the token you just created) and the chatid value (for the chatid previously noted); also set the URL to your moodle instance URL

          curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatid=5&wsfunction=mod_chat_get_sessions&showall=0&wstoken=12a2a65aeea2a177055e233f9e303218' | python -m "json.tool"

      1. You should not receive any sessions
      2. Set 'showall' argument in the request to '1' instead of '0' and execute the curl request again
      3. You should recieve one session with the field iscomplete set to false
      4. Now, using two different students account in the course access to the chat (you may use different browsers, or the incognito mode in a different tab)
      5. Write some messages using the two students accounts (keep the chat open at least one minute and then write one last message and quit)
      6. Now, wait 5 minutes and execute the curl request with showall set to 0
      7. Confirm that now you see the session with the field iscomplete set to true
      8. You can compare the result of the request with the "View past chat sessions page" in Moodle web for the chat, you should see the same users and number of messages that are listed there (the number just after the user name is the number of messages)
      9. Now, execute the following request replacing the chatid (with the course chat instance id, the one you noted before) and the sessionstart and sessionend values with the ones returned by the previous curl request. You can use the wstoken for the previous request. Remember to replace the URL as well

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatid=5&wsfunction=mod_chat_get_session_messages&sessionstart=1505987150&sessionend=1505987503&wstoken=12a2a65aeea2a177055e233f9e303218' | python -m "json.tool"

      10. And check that you receive the same messages that the one listed in the Moodle web page when you click the "See this session" link in the session list page. Note that for system messages like "beep", "enter", "exit" in the Moodle web interface you will see English strings describing the action like "Someone has just entered this chat"
      11. Now, ensure that all the users are logged-out from the chat in the site
        #. Wait 5 minuts and repeat steps 10 and 11
      12. Execute again the WS request from 6 and check that this time you receive at least 2 sessions
      13. Access to the activity in Moodle as a teacher and check that you can see in “View past chat sessions” the sessions and if you enter in each one of them, you see the messages you sent in those sessions
      Show
      As admin go to Site administration > Plugins > Activity modules > Chat and check that the "Chat method" field is set to "Ajax method" As teacher create a chat activity with "Everyone can view past sessions" set to "Yes" As student enrolled in the course where is the chat access to the chat, write one message, note the 'id' in the popup URL (you will need it later) and close the chat popup window As admin, enable "Enable web services for mobile devices", you can find the option in Site administration ► Mobile app ► Mobile settings Create a Token in the mobile app service for the student: Click on Site administration ► Plugins ► Web services ► Manage tokens Next, in the command line interface, you can do a CURL REST call simulating a WS client with the user. You need to replace the wstoken value (for the token you just created) and the chatid value (for the chatid previously noted); also set the URL to your moodle instance URL curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatid=5&wsfunction=mod_chat_get_sessions&showall=0&wstoken=12a2a65aeea2a177055e233f9e303218' | python -m "json.tool" You should not receive any sessions Set 'showall' argument in the request to '1' instead of '0' and execute the curl request again You should recieve one session with the field iscomplete set to false Now, using two different students account in the course access to the chat (you may use different browsers, or the incognito mode in a different tab) Write some messages using the two students accounts (keep the chat open at least one minute and then write one last message and quit) Now, wait 5 minutes and execute the curl request with showall set to 0 Confirm that now you see the session with the field iscomplete set to true You can compare the result of the request with the "View past chat sessions page" in Moodle web for the chat, you should see the same users and number of messages that are listed there (the number just after the user name is the number of messages) Now, execute the following request replacing the chatid (with the course chat instance id, the one you noted before) and the sessionstart and sessionend values with the ones returned by the previous curl request. You can use the wstoken for the previous request. Remember to replace the URL as well curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'chatid=5&wsfunction=mod_chat_get_session_messages&sessionstart=1505987150&sessionend=1505987503&wstoken=12a2a65aeea2a177055e233f9e303218' | python -m "json.tool" And check that you receive the same messages that the one listed in the Moodle web page when you click the "See this session" link in the session list page. Note that for system messages like "beep", "enter", "exit" in the Moodle web interface you will see English strings describing the action like "Someone has just entered this chat" Now, ensure that all the users are logged-out from the chat in the site #. Wait 5 minuts and repeat steps 10 and 11 Execute again the WS request from 6 and check that this time you receive at least 2 sessions Access to the activity in Moodle as a teacher and check that you can see in “View past chat sessions” the sessions and if you enter in each one of them, you see the messages you sent in those sessions

      To retrieve chat past sessions we'd need two web services:

      • mod_chat_get_sessions: To list all the chat sessions for the given chat
      • mod_chat_get_session_messages: To get the chat messages from one chat session

            jleyva Juan Leyva
            jleyva Juan Leyva
            Pau Ferrer Pau Ferrer
            David Monllaó David Monllaó
            Janelle Barcega Janelle Barcega
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.