Author |
Post |
|
#1 Mon Aug 17, 2009 14:08, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
|
Hello,
I'm trying to make an sms forwarding service. I finally made sms server tools3 functioning (thanks Keke & God).
I've already defined the queues and provider section in my smsd.conf. I also tried it with sendsms and tried sending a message to different operator and it was successfully sent using the defined queues and provider.
The objective of this sms forwarding is to make use of the no-limit texting subscription offered by the operators. Same network text message will be unlimited so I'm thinking if sms server tools3 can transfer a message received in the incoming folder and classify it according to the access code (63939, 63917, etcs) and send the message through that modem that is same with the final destination of the message.
|
|
#2 Mon Aug 17, 2009 14:25, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
I made an illustration in case my post above isn't clear... illustration
|
|
#3 Mon Aug 17, 2009 17:00, 188 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
Your plan differs a lot from your original plan. Anyways, here is an eventhandler script (sample, as usual  ) for your purpose: #!/bin/bash
debug=1
if [ "$1" = "RECEIVED" ]; then
COUNTRY_CODE=63 FORWARD_TO="" TEXT=`sed -e '1,/^$/ d' < "$2"`
# Make an array of words and get the key: words=($TEXT) key=${words[0]}
# Check if the key is an acceptable phone number: tmp=${key:0:${#COUNTRY_CODE}} if [ "$tmp" = "$COUNTRY_CODE" ]; then # International format, ok: FORWARD_TO="$key" else tmp=${key:0:1} if [ "$tmp" = "0" ]; then # National format, add the country code and remove first zero: FORWARD_TO="$COUNTRY_CODE${key:1}" fi fi
if [ $debug -gt 0 ]; then echo "FORWARD_TO: $FORWARD_TO" fi
if [ "x$FORWARD_TO" != "x" ]; then
# Remove the key and one space from the start of a message body: TEXT=${TEXT:$((${#key} + 1))}
if [ $debug -gt 0 ]; then echo "TEXT: $TEXT" fi
# Create a new message file to send: FILE=`mktemp /tmp/send_XXXXXX` echo "To: $FORWARD_TO" >> $FILE echo "" >> $FILE echo -n "$TEXT" >> $FILE
if [ $debug -gt 0 ]; then cat $FILE echo "" rm $FILE else FILE2=`mktemp /var/spool/sms/outgoing/send_XXXXXX` mv $FILE $FILE2 fi fi fi 'bash' Syntax Highlight powered by GeSHi Queue sorting will do the rest. In your illustration you use national number format. This is probably a good choice for users, but inside your system you should always use international format. This script will accept both formats and will change national format to international if necessary. If the format of SMS is not recognized, the script does nothing. Probably there should be some kind of handling for errors, which means that you have to write something more... As usual, first run your newly created eventhandler manually to see how it works. There are some lines for debugging purposes. Later you can change debug=1 to debug=0. 
|
|
#4 Mon Aug 17, 2009 18:12, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
Wow, thanks a lot keke! I'm gonna try that now. Yes my plan changed a bit :, but still i'm gonna pursue the webform thinggy.  At first i thought of using sed and take out the destination # and message from the received message and create a new file in the outgoing directory. I'm actually reading scripting book right now but I'm having a hard time understanding it and it just makes me sad
|
|
#5 Sat Aug 22, 2009 16:50, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
Hello, I also would like to add "powered by myWebsite" on the sms forwarding script. How would I achieve this?
|
|
#6 Sun Aug 23, 2009 12:35, 188 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
Before writing $TEXT to the file, modify it using the following code:
|
|
#7 Mon Aug 24, 2009 18:20, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
Thanks so much keke!
I ran the service and had some of my friends test it, however, when I checked the logs and did a peek through the failed folder, there were a lot of them. I was thinking, is there a way as to how I can notify the sender that the message they've sent was not sent for some reason, by checking the failed folder?
and or just a simple reply that their message has been received by sms3 and that is is being/aready sent?
TIA
|
|
#8 Tue Aug 25, 2009 18:13, 188 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
kaloyzki wrote I was thinking, is there a way as to how I can notify the sender that the message they've sent was not sent for some reason, by checking the failed folder?
Yes, you should check messages in the failed folder. There is a Fail_reason header included in each message. As you have lot of failed messages, you can see why they are failed and decide what is a permanent reason and what messages could be tried to re-send. There is a sample script smsresend in the script directory of a package. Please check it. If you do not want to create any re-sending mechanism, you can notify the original sender about the failing. However, if the message was forwarded, you need to include some additional header in the original message file, for example Received_from. With this you can know where to send a failure report. Remember that there is RECEIVED, SENT and FAILED arguments available in the eventhandler script. For example, with each SENT message you can check if there is a Received_from header, and if there is, you can send a reply which tells that SMS has been successfully sent.
|
|
#9 Tue Aug 25, 2009 20:50, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
Thanks keke, you have been very helpful!
I'm thinking of adding registration to this forwarding script. But as always, I'm having a very difficult time. Sigh. Currently studying how to get this working.
|
|
#10 Fri Aug 28, 2009 09:45, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
Woops, I got confused. I thought the senders number is being included in every message sent. Since I was sending from my phone and receiving from my phone, but it wasn't all along. So how do I make it work so that every forwarded message will include the original senders number?
|
|
#11 Fri Aug 28, 2009 16:59, 188 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
Sorry, but perhaps I did not understand you now...
Sent message has a destination number stored by default. You can store any additional headers depending on your needs.
When you receive a message which is going to be forwarded, you already have an eventhandler code which can take senders number to the variable (usually $FROM). When you forward this message, you create a new message file which contains a new destination which is picked up from the message body. You write "To: <new destination>" to the message file. Using the similar command you can write for example a header "Received_from" containing a content of $FROM variable.
Or?
|
|
#12 Fri Aug 28, 2009 17:32, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
Sorry bout that confusing statement. Anyway, I'm trying to figure out how I can make it appear that the forwarded message will contain the number that originally sent the message. example: powered by myWebsite. SM from: 09151234567 message: hello world Is it also possible to format the message in such a way that it will appear like the example given above? I tried making the above example but I'm a bit confused. If I add the $KEY, the value of it is already the FORWARD_TO. How do I make it FROM?
|
|
#13 Sat Aug 29, 2009 14:24, 188 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
kaloyzki wrote example: powered by myWebsite. SM from: 09151234567 message: hello world
Is it also possible to format the message in such a way that it will appear like the example given above?
You can get senders number using this command: FROM=`formail -zx From: < $2`It's in international format. If you want to change it to the national format, you can use this kind of command: FROM=`echo "$FROM" | sed 's/^63/0/g'`Your example message can be created like this:
|
|
#14 Sun Aug 30, 2009 21:28, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
Hello, I'm trying to add additional feature to this sms forwarding. I'm working on making the sender follow a format to be able to use the service by composing a short message following this format: txt<space>09151234567<space>message If the format is incorrect, it'll send an error reply. If it's correct, it'll reply with a "message being sent". But I can't seem to make it work... The code below is the one I'm messin with.
|
|
#15 Sun Aug 30, 2009 22:05, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
Okay so now I was able to make sms3 reply whenever the format is correct and also whenever it is not followed. But the problem is whenever the format is not followed, it gives a reply that the message format is incorrect and it still forwards the message. And whenever the format is followed, it gives a reply that the message is now being sent but the message is not forwarded at all. Here's the code btw: I'm confused... I want it the other way around.  « Last edit by kaloyzki on Sun Aug 30, 2009 22:07, 188 months ago. »
|
|
#16 Mon Aug 31, 2009 21:59, 188 months ago.
|
Member
Registered: Jun 2009
Location: Manila, Philippines
Topic owner
|
I was able to make the sender receive a confirmation of message received but I still cannot make the script check if the format is correct then if its correct. if txt format = correct send a confirmation of message received to the sender elif forwards the message to the destination else sorry incorrect format. fi how? 
|
|
#17 Wed Sep 02, 2009 18:15, 188 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
kaloyzki wrote And whenever the format is followed, it gives a reply that the message is now being sent but the message is not forwarded at all.
Now when you have an additional parameter "txt" in your message format, you can of course write a new script from scratch, but you could also modify and use the script shown in the post #3 of this topic. There is an array of words from the message. First word was previously a destination number, but now in your usage it is the key. Place a new variable to the script: number=${words[1]}, after key=${words[0]}. Change the previously used variable name (key) to number. You can now check the key and make the actions required. Click here for instructions. When a message is going to be forwarded, the next one code does not give an expected result anymore: # Remove the key and one space from the start of a message body: TEXT=${TEXT:$((${#key} + 1))}Because there are more keywords and probably more than one space for each of them, you could use this kind of code: TEXT=`echo "$TEXT" | sed -e '1s/^ *[^ ]* //g'` TEXT=`echo "$TEXT" | sed -e '1s/^ *[^ ]* //g'` TEXT=`echo "$TEXT" | sed -e '1s/^ *//g'`First command will remove the first word and the second command will remove the second word. Later when you add some keywords, you can easily copy those lines. Last command will remove spaces from the begin of a text and your forwarded message will look good.  For more processing of a text (signature etc.), use the instructions given before, they are still valid.
|