-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
74 lines (63 loc) · 2.17 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using ScgApi;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace send_mms
{
class Program
{
static async Task<String> CreateAndUploadAttachment(Session session, String path)
{
var res = Attachment.Resource(session);
var id = await res.Create(new Attachment()
{
Name = "test_upload",
Filename = "cutecat.jpg",
Type = "image/jpeg"
});
await res.Upload(id, path);
Console.WriteLine("Created attachment {0}", id);
return id;
}
static async Task SendMms(String senderId, String receipient, String body,
String attachmentPath, SessionOptions opts)
{
using (var session = new Session(opts))
{
var res = MessageRequest.Resource(session);
String id = await res.Create(new MessageRequest()
{
From = "sender_id:" + senderId,
To = new List<String>() { receipient },
Body = body,
Attachments = new List<string>()
{
await CreateAndUploadAttachment(session, attachmentPath)
}
});
Console.WriteLine("Created message request {0}", id);
}
}
static void Main(string[] args)
{
if (args.Length < 4)
{
Console.WriteLine("Usage: send_mms senderid receipient message attachment-path [auth-file] [api-url]");
return;
}
var opts = new SessionOptions();
if (args.Length > 4)
opts.AuthFilePath = args[4];
if (args.Length > 5)
opts.BaseUrl = args[5];
try
{
SendMms(args[0], args[1], args[2], args[3], opts).Wait();
}
catch (Exception ex)
{
Console.WriteLine("Failed: {0}", ex.ToString());
}
}
}
}