shadow9449
Registered User.
- Local time
- Today, 17:05
- Joined
- Mar 5, 2004
- Messages
- 1,032
String to date conversion works perfectly. Thanks once again!
Well I'd try right at the end with csv?, but then I have only used it on non download urls, but worth a try?![]()
1. I used a timer event as stated in an earlier post to check for received messages every 5 minutes. The code ensures only messages received in that time are imported to prevent duplication. The app does NOT need to be restarted for this to work.
2. It also works for received voice messages and optionally downloads a transcription of the messages or a recording.
3. As previously mentioned I chose to use CSV as it is the default and because at the time I did this I knew very little about working with XML or JSON. One year later and I'd probably use JSON.
4. As CSV is the default it doesn't have to be specified. From memory, if using XML you need to end the GET statement with ?xml
Ah - clearly I'm special!1. I don't get why it works for you but not for me! I did solve this, though. More about that later.
2. I note that you are receiving voice messages as well. Is there documentation somewhere that is compatible with Access VBA users? As I've said, Twilio is thoroughly documented but other than one blog post I haven't seen anything for us Access users. Are you able to do cool stuff like automating calls and responses (e.g. the message says "press 1 to confirm and 2 to cancel" and then import the results? I see that it can be done using Python on a cloud server but nothing about Access.
Sorry - clearly my memory was faulty on that3. I just tested it without the .csv and it downloaded in XML
For whatever reason, its never been an issue for me - I used CSV and then later tested using JSON output - didn't bother with XML4. So, after hours of looking online I found a post on a blog that says that XMLHTTP60 caches for some historic reason and you have to clear the cache by calling a random URL (I've seen many posts on this topic with people having the same problem) whereas ServerXMLHTTP does not have the problem. I took a stab at it by replacing the mentions of XMLHTTP with ServerXMLHTTP and it works perfectly. I hope there is no downside but I've been testing it all day and it's working flawlessly.
Dim http As MSXML2.XMLHTTP60
'MessageUrl = GetBaseURL() & "/2010-04-01/Accounts/" & GetMessageAccountSID() & "/Messages.csv"
'filter for received messages sent after last message check e.g.
'MessageUrl = GetBaseURL() & "/2010-04-01/Accounts/" & GetMessageAccountSID() & "/Messages.csv?To=44.....&DateSent>=2017-02-11"
strCriteria = "/Messages.csv?&To=" & GetTrimmedFromPhoneNumber() & "&DateSent>=" & GetModifiedLastReceivedSMSMessageCheck() & ""
'Debug.Print strCriteria
MessageUrl = GetBaseURL() & "/2010-04-01/Accounts/" & GetMessageAccountSID() & GetCriteria()
'Debug.Print MessageUrl
' setup the request and authorization
Set http = New MSXML2.XMLHTTP60
http.Open "GET", MessageUrl, False, GetMessageAccountSID(), GetMessageAuthToken()
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.Send ""
'Debug.Print http.responseText
5 I've written a complete SMS inbox with a little popup notification set on a 1 minute timer and it's really a nice project. Once again, thank you, Colin. I could not have done it without you.
The only documentation found for Access was the article I told you about previously
You're welcome - it would be interesting to see what you've done
For info I've attached a PDF which I created as a user guide for this feature - to reduce file size, image quality was also reduced
There is a separate guide for setting up the feature
Ok and how did you modify the SMS send code to enable sending voice messages?
Function MakeCall(FromNumber As String, ToNumber As String, Message As String)
On Error GoTo Err_Handler
If IsLoaded("frmSendMessageTest") Then Forms!frmSendMessageTest.lblInfo.visible = False
'get start time - needed here to calculate duration of call
dblStart = CDbl(Now())
' setup the URL
CallUrl = GetBaseURL() & "/2010-04-01/Accounts/" & GetMessageAccountSID() & "/Calls"
' setup the request and authorization
Set http = New MSXML2.XMLHTTP60
http.Open "POST", CallUrl, False, GetMessageAccountSID(), GetMessageAuthToken()
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
PostData = "From=" & URLEncode(FromNumber) _
& "&To=" & URLEncode(ToNumber) _
& "&Url=http://twimlets.com/message?Message=" & URLEncode(URLEncode(Message, True))
'Debug.Print postData
' send the POST data
http.Send PostData
' optionally write out the response if you need to check if it worked
'Debug.Print http.Status
'Debug.Print http.responseText
'calculate time taken
dblEnd = CDbl(Now())
strTimeTaken = Format(CDate(dblEnd - dblStart), "hh:mm:ss")
lngDuration = CDbl(DateDiff("s", CDate(dblStart), CDate(dblEnd)) / 60) 'duration in minutes
'Debug.Print dblStart; dblEnd; strTimeTaken; lngDuration
strHTTPResponseText = Replace(http.responseText, "><", ">" & vbNewLine & "<")
intHTTPStatus = http.Status
'Debug.Print strHTTPResponseText
'setup message response text
Select Case intHTTPStatus
Case 201 'success
int201 = int201 + 1
'Debug.Print strHTTPResponseText
Case 400 'bad request
int400 = int400 + 1
strErrorText = "Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _
"===================================================" & vbNewLine & _
"HTTP response text: " & strHTTPResponseText
Case 401 'unauthorised
int401 = int401 + 1
If strErrorText <> "" Then
strErrorText = strErrorText & vbNewLine & vbNewLine & _
"Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _
"===================================================" & vbNewLine & _
"HTTP response text: " & strHTTPResponseText
Else
strErrorText = "Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _
"===================================================" & vbNewLine & _
"HTTP response text: " & strHTTPResponseText
End If
Case Else 'other failure
intOther = intOther + 1
If strErrorText <> "" Then
strErrorText = strErrorText & vbNewLine & vbNewLine & _
"Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _
"===================================================" & vbNewLine & _
"HTTP response text: " & strHTTPResponseText
Else
strErrorText = "Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _
"===================================================" & vbNewLine & _
"HTTP response text: " & strHTTPResponseText
End If
End Select
Exit_Handler:
On Error Resume Next
' clean up
Set http = Nothing
Exit Function
Err_Handler:
Select Case Err.Number
Case NOINTERNETAVAILABLE
MsgBox "Connection to the internet cannot be made or " & _
"Twilio website address is wrong"
Case Else
MsgBox "Error: " & Err.Number & "; Description: " & Err.Description
Resume Exit_Handler
End Select
End Function
I've attached images of the Inbox as well as the notification. The latter is on a 3 second transparancy fade in/fade out.
This was the main part of the code though there lots else to it as well
Code:Function MakeCall(FromNumber As String, ToNumber As String, Message As String) On Error GoTo Err_Handler If IsLoaded("frmSendMessageTest") Then Forms!frmSendMessageTest.lblInfo.visible = False 'get start time - needed here to calculate duration of call dblStart = CDbl(Now()) ' setup the URL CallUrl = GetBaseURL() & "/2010-04-01/Accounts/" & GetMessageAccountSID() & "/Calls" ' setup the request and authorization Set http = New MSXML2.XMLHTTP60 http.Open "POST", CallUrl, False, GetMessageAccountSID(), GetMessageAuthToken() http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" PostData = "From=" & URLEncode(FromNumber) _ & "&To=" & URLEncode(ToNumber) _ & "&Url=http://twimlets.com/message?Message=" & URLEncode(URLEncode(Message, True)) 'Debug.Print postData ' send the POST data http.Send PostData ' optionally write out the response if you need to check if it worked 'Debug.Print http.Status 'Debug.Print http.responseText 'calculate time taken dblEnd = CDbl(Now()) strTimeTaken = Format(CDate(dblEnd - dblStart), "hh:mm:ss") lngDuration = CDbl(DateDiff("s", CDate(dblStart), CDate(dblEnd)) / 60) 'duration in minutes 'Debug.Print dblStart; dblEnd; strTimeTaken; lngDuration strHTTPResponseText = Replace(http.responseText, "><", ">" & vbNewLine & "<") intHTTPStatus = http.Status 'Debug.Print strHTTPResponseText 'setup message response text Select Case intHTTPStatus Case 201 'success int201 = int201 + 1 'Debug.Print strHTTPResponseText Case 400 'bad request int400 = int400 + 1 strErrorText = "Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _ "===================================================" & vbNewLine & _ "HTTP response text: " & strHTTPResponseText Case 401 'unauthorised int401 = int401 + 1 If strErrorText <> "" Then strErrorText = strErrorText & vbNewLine & vbNewLine & _ "Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _ "===================================================" & vbNewLine & _ "HTTP response text: " & strHTTPResponseText Else strErrorText = "Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _ "===================================================" & vbNewLine & _ "HTTP response text: " & strHTTPResponseText End If Case Else 'other failure intOther = intOther + 1 If strErrorText <> "" Then strErrorText = strErrorText & vbNewLine & vbNewLine & _ "Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _ "===================================================" & vbNewLine & _ "HTTP response text: " & strHTTPResponseText Else strErrorText = "Message failed with HTTP status error " & http.Status & " " & http.statusText & vbNewLine & _ "===================================================" & vbNewLine & _ "HTTP response text: " & strHTTPResponseText End If End Select Exit_Handler: On Error Resume Next ' clean up Set http = Nothing Exit Function Err_Handler: Select Case Err.Number Case NOINTERNETAVAILABLE MsgBox "Connection to the internet cannot be made or " & _ "Twilio website address is wrong" Case Else MsgBox "Error: " & Err.Number & "; Description: " & Err.Description Resume Exit_Handler End Select End Function
The part you are likely to ask about is the PostData section - if so, I'll need to study it to remind myself what it all means!
I also used separate functions to log all messages (both text & voice)
Looks good. Was that a system tray notification (balloon text)?
If so did you manage to make it interactive i.e. click on it to do something?
h = GetSystemMetrics32(1) * TwipsPerPixelY
i = GetSystemMetrics32(0) * TwipsPerPixelX
1. Ok I'm just posting to say that I used your function and it worked out of the box. That's brilliant!
2. Sooo....how do you pick up the call log? is it the same GET as to the SMS but to the /Calls URL?
3. I see that Twilio has faxing as well. Have you seen code that can fax an Access report?
I see that you are using Twimlets. Does that require the user to set it up on the Twilio account or is that just the URL that you hit with the POST message?
3. Faxing!!!! I thought we were moving forward not reverting to old technology! Why on earth would you want to fax a report? Save as PDF and email as an attachment
I'm not trying to be awkward but I coded all of this over a year ago. I really can't remember
Once again, the answers must be somewhere in the API documentation
I couldn't agree more but there are MANY offices, especially in the medical industry, who are stuck in the 80s and use faxing far more than email.
A fax printer driver is supplied with Windows. Why not use that?
Around 20 years ago I used it regularly .... before email came along.
Do you need a specific type of phone line or modem or does it just use the internet to send faxes? I don't know a lot about the topic.