Sends a message. The message ID or error code will be returned in the content of the Page. If multiple numbers are submitted, then multiple IDs / error codes will be returned, separated by commas
상속: BaseSendMessageRequest
예제 #1
0
        private static void CompileCommand(string[] args)
        {
            var client = new FastSmsClient("6Rx6-stiU-a8sY-vt9i");
            var commandArguments = args;
            if (!commandArguments.Any())
                return;
            var command = commandArguments[0];

            switch (command)
            {
                case "CheckCredits":
                    Console.WriteLine(client.CheckCredits());
                    break;
                case "CheckMessageStatus":
                    if (commandArguments.Length != 2)
                        Console.WriteLine(ArgumentError);
                    else
                        Console.WriteLine(client.CheckMessageStatus(commandArguments[1]));
                    break;
                case "UpdateCredits":
                    int i;
                    if (commandArguments.Length != 3 || !int.TryParse(commandArguments[2], out i))
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.UpdateCredits(commandArguments[1], i);
                        Console.WriteLine(Success);
                    }
                    break;
                case "DeleteAllContacts":
                    if (commandArguments.Length != 1)
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.DeleteAllContacts();
                        Console.WriteLine(Success);
                    }
                    break;
                case "DeleteAllGroups":
                    if (commandArguments.Length != 1)
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.DeleteAllGroups();
                        Console.WriteLine(Success);
                    }
                    break;
                case "EmptyGroup":
                    if (commandArguments.Length != 2)
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.EmptyGroup(commandArguments[1]);
                        Console.WriteLine(Success);
                    }
                    break;
                case "DeleteGroup":
                    if (commandArguments.Length != 2)
                        Console.WriteLine(ArgumentError);
                    else
                    {
                        client.DeleteGroup(commandArguments[1]);
                        Console.WriteLine(Success);
                    }
                    break;
                case "CreateUser":
                    if (commandArguments.Length != 3)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var user = new CreateUserRequest(commandArguments[1], commandArguments[2])
                        {
                            LastName = "User Last name",
                            AccessLevel = "Normal",
                            ChildPassword = "******",
                            Email = @"*****@*****.**",
                            Credits = 100
                        };
                        client.CreateUser(user);
                        Console.WriteLine(Success);
                    }
                    break;
                case "SendMessageToUser":
                    if (commandArguments.Length != 3)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var message = new SendMessageToUserRequest()
                        {
                            Body = commandArguments[1],
                            DestinationAddress = commandArguments[2]
                        };
                        client.SendMessage(message);
                        Console.WriteLine(Success);
                    }
                    break;
                case "SendMessageToGroup":
                    if (commandArguments.Length != 3)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var message = new MessageToGroupRequest()
                        {
                            Body = commandArguments[1],
                            GroupName = commandArguments[2]
                        };
                        client.SendMessage(message);
                        Console.WriteLine(Success);
                    }
                    break;
                case "SendMessageToList":
                    if (commandArguments.Length != 3)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var message = new SendMessageToListRequest()
                        {
                            Body = commandArguments[1],
                            ListName = commandArguments[2]
                        };
                        client.SendMessage(message);
                        Console.WriteLine(Success);
                    }
                    break;
                case "GetReports":
                    if (commandArguments.Length != 4)
                    {
                        Console.WriteLine(ArgumentError);
                    }
                    else
                    {
                        var reportType = ReportType.Messages;
                        switch (commandArguments[1])
                        {
                            case "InboundMessages":
                                reportType = ReportType.InboundMessages;
                                break;
                            case "Messages":
                                reportType = ReportType.Messages;
                                break;
                            case "Outbox":
                                reportType = ReportType.Outbox;
                                break;
                            case "Usage":
                                reportType = ReportType.Usage;
                                break;
                        }
                        var reports = client.GetReports(reportType, commandArguments[2], commandArguments[3]);
                        foreach (var report in reports)
                        {
                            Console.WriteLine(ReportToString(report));
                        }
                    }
                    break;
                case "Help":
                    Help();
                    break;
                default:
                    break;
            }
        }
예제 #2
0
        /// <summary>
        ///    Sends a message. The message ID or error code will be returned in the content of the Page. 
        ///    If multiple numbers are submitted, then multiple IDs / error codes will be returned, separated by commas.
        /// </summary>
        /// <param name="messageToUser">Message model</param>
        /// <returns>Id of sent message.</returns>
        public string SendMessage(SendMessageToUserRequest messageToUser)
        {
            var validityPeriod = 86400;
            if (messageToUser.ValidityPeriod != null && messageToUser.ValidityPeriod > 0 && messageToUser.ValidityPeriod <= 86400)
                validityPeriod = (int)messageToUser.ValidityPeriod;

            var requestUrl = string.Format("{0}{1}&Action=Send&DestinationAddress={2}&SourceAddress={3}&Body={4}&ScheduleDate={5}&SourceTON={6}&ValidityPeriod={7}" +
                                            "&GetAllMessageIDs={8}&GetBGSendID{9}",
                ApiUrl, _token, messageToUser.DestinationAddress, messageToUser.SourceAddress, messageToUser.Body,
                messageToUser.ScheduleDate, messageToUser.SourceTon, validityPeriod, messageToUser.GetAllMessageIDs,
                messageToUser.GetBgSendId);

            var messageId = _httpClient.GetResponse(requestUrl);

            if (FastSmsErrors.Errors.Keys.Contains(messageId))
            {
                throw new FastSmsException(messageId);
            }

            return messageId;
        }