MyChat add-ons: developing, technical questions, testing, documentation and other useful information
User avatar
Alona Kutsenko
The work scheme is the following:
  1. Creat the folder "c:\messages\broadcast\" on a computer with MyChat Server.
  2. Add text files made in a regular Notepad to this folder. File names are a time when messages should be sent. For example, "17.35.txt" or "8.00.txt". Notepad adds the extension .txt automatically when saving the file, the time must be multiple of five minutes.
  3. Create one or several users groups on MyChat Server and add people for whom you want to send notifications.
  4. Create a script on the event "User defined scripts", "Every 5 minutes"; enable the script.
  5. Profit!
How it looks like in the scripts editor:

broadcast-for-groups.png
Script for sending notifications from text files for a group of people in MyChat
broadcast-for-groups.png (82.6 KiB) Viewed 13501 times

Script source
Code: Select all
// ---------------------------------------
// Script created by Alexey Pikurov ([email protected])
// sending notifications on time from text files
// for specified groups of people
// 15.09.2018 14:13:00
// ---------------------------------------

const
  sGroupsList = 'Special'; // users groups, divided by commas, no spaces
  sPath = 'c:\messages\broadcast\'; // path on the server disk to take files for notifications
var
  sFullName, sFileName, sMsg, sUsersList, sCurrentGroup, sGroupsOriginal: string;
  iDay: integer;
  bFlag: boolean;
begin
  iDay := DayOfTheWeek(Now);
  sFileName := FormatDatetime('hh.nn', Now) + '.txt'; // for example, 17.45.txt
 
  sGroupsOriginal := sGroupsList;
 
    while length(sGroupsOriginal) > 0 do begin
      sCurrentGroup := GetNextSt(sGroupsOriginal, ',');

      sFullName := sPath + sFileName;
     
        if FileExists(sFullName) then
          if iDay < 6 then begin // run the script on workdays only
            sMsg := Trim(LoadTextFromFile(sFullName, 0));
     
            if length(sMsg) > 0 then begin
              sUsersList := mGetUsersListInGroupsByNames(sCurrentGroup);
         
                if length(sUsersList) > 0 then
                  mSendBroadcast(sMsg, sUsersList, EndOfTheDay(Now), 1);
            end; 
          end;
    end;
end.