Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send SMS ? #99

Open
luc-github opened this issue Oct 11, 2018 · 16 comments
Open

How to send SMS ? #99

luc-github opened this issue Oct 11, 2018 · 16 comments

Comments

@luc-github
Copy link

luc-github commented Oct 11, 2018

Hello,
First thank you for such nice project it is really great,
before I was using Skype4Py for sending SMS for Pethospital appointment, I was hopping there is same feature in SkPy

I have tried the web.skype.com and it allows it, so should be possible

I see in doc chat.rst there is SMS capability

"properties": {"capabilities": ["AddMember",
                                         "ChangeTopic",
                                         "ChangePicture",
                                         "EditMsg",
                                         "CallP2P",
                                         "SendText",
                                         "SendSms",
                                         "SendFileP2P",
                                         "SendContacts",
                                         "SendVideoMsg",
                                         "SendMediaMsg",
                                         "ChangeModerated"],

but I do not see in code the function allowing doing it .
Is this feature available ? If not, how to add it ?
Thanks,

@Terrance
Copy link
Owner

Not at present -- I don't have Skype SMS set up on my account, so I'm unsure what any of the API calls look like.

If you're able to do it from Skype for Web and track the HTTP requests it makes, we can look into reproducing it here, though it may be tricky to test locally.

@luc-github
Copy link
Author

When you have skype credit you can call or sms a phone number. same windows as chat.
Ok. For what can see in google developer tools in network tab there are several exchanges . I will try to isolate the communication process and understand how skpy works

@jeffersonveloso
Copy link

Any news about this demand?

@Terrance
Copy link
Owner

My request above still stands, as I've not touched Skype since then, let alone the SMS parts.

@jeffersonveloso
Copy link

Meu pedido acima ainda está de pé, já que não toquei no Skype desde então, muito menos nas partes do SMS.

I can even create the chat and send an sms but after a few seconds it appears in the sms above the delivery failed, I don't know what it can be.
statussms

@Terrance
Copy link
Owner

I can even create the chat and send an sms

With SkPy, or in Skype for Web?

If you can successfully send a message with the latter but not the former, please get a sample HTTP request from your browser so we can tell what it's doing differently. Without that I don't know what needs to change.

@jeffersonveloso
Copy link

Posso até criar o chat e enviar um sms

Com o SkPy ou no Skype para Web?

Se você conseguir enviar uma mensagem com o último, mas não com o primeiro, obtenha um exemplo de solicitação HTTP de seu navegador para que possamos saber o que está fazendo de diferente. Sem isso, não sei o que precisa mudar.

I checked the request on the web and tried to reproduce it on SkyPy the request creates the chat with the number and sends the sms but after a few seconds it gets the message as in the photo above you want it to send as is the headers, body and which endpoint make the requisition?

@Terrance
Copy link
Owner

headers, body and which endpoint

All of the above, same as what you'd get using SKPY_DEBUG_HTTP=1 with SkPy.

@jeffersonveloso
Copy link

headers, body and which endpoint

All of the above, same as what you'd get using SKPY_DEBUG_HTTP=1 with SkPy.

The parameter requestId is a str(uuid4()).

**HEADERS**

Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6
Authentication: skypetoken=eyJhbGciOiJSUzI1NiIsImtpZCI6IjEwMiIsIng1dCI6IjNNSnZRYzhrWVNLd1hqbEIySmx6NTRQVzNBYyIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTQyOTI0NzMsImV4cCI6MTYxNDM3ODg2OSwic2t5cGVpZCI6ImxpdmU6bmVnb2Npb3NhcHBsZSIsInNjcCI6OTU4LCJjc2kiOiIxNjE0MjkyNDY5IiwiY2lkIjoiZDYzZDRmM2MxN2VlNGZhMiIsImFhdCI6MTYxNDI2ODc5Nn0.d-WH5Y1kDw3uPOW0CX1YfPqBJdICZ_Ov0FTQvnsMtv9B00ulhK_w9ckc18-8t69-F-NiQ84DhSvgOYZ0fNwtilOJgp7SU6tjG0F1mSlGv8dDhMRhHJZUI2LHBO8x-Nb3bemKyqqpiJUEg5M_NFz3NWzjdXoSlSKEjSfcHeq2JrIAD3aJSVrX7rrtNUu0xzjIjJyNrySwltcC_7xvHYvxmGs2QZfmEAxpwLU5o1HqI7qncduW0hpUDcvjt2SSTPfgoI8twMnxEITsQivC1K7xjJBoP4kjEtMiU11R7bIGKPk2lyr92LKvaF0sT3fJG1p5uI0WtaC4wNIgohUbFU8SLg
BehaviorOverride: redirectAs404
ClientInfo: os=Windows; osVer=10; proc=x86; lcid=pt-BR; deviceType=1; country=US; clientName=skype4life; clientVer=1418/8.68.0.96//skype4life; timezone=America/Sao_Paulo
Connection: keep-alive
Content-Length: 759
Content-Type: application/json
Host: azeus1-client-s.gateway.messenger.live.com
Origin: https://web.skype.com
Referer: https://web.skype.com/
RegistrationToken: registrationToken=U2lnbmF0dXJlOjI6Mjg6QVFRQUFBQVkwYThDWDJYUmFCUE9yNUJ6cERQQTtWZXJzaW9uOjY6MToxO0lzc3VlVGltZTo0OjE5OjUyNDkxODQ5MTEyMzk1NjQ4ODk7RXAuSWRUeXBlOjc6MTo4O0VwLklkOjI6MTg6bGl2ZTpuZWdvY2lvc2FwcGxlO0VwLkVwaWQ6NTozNjo2YmM2NDExZS00MWE3LTQ4NDEtYTg1Yi0zNmMyMGQ3MjJhM2U7RXAuTG9naW5UaW1lOjc6MTowO0VwLkF1dGhUaW1lOjQ6MTk6NTI0OTE4NDkxMTIzOTQwODY3NTtFcC5BdXRoVHlwZTo3OjI6MTU7RXAuRXhwVGltZTo0OjE5OjUyNDkxODU3NzUxMTczODc5MDQ7VXNyLk5ldE1hc2s6MTE6MToyO1Vzci5YZnJDbnQ6NjoxOjA7VXNyLlJkcmN0RmxnOjI6MDo7VXNyLkV4cElkOjk6MTowO1Vzci5FeHBJZExhc3RMb2c6NDoxOjA7VXNlci5BdGhDdHh0OjI6NDE2OkNsTnJlWEJsVkc5clpXNFNiR2wyWlRwdVpXZHZZMmx2YzJGd2NHeGxBUU5WYVdNVU1TOHhMekF3TURFZ01USTZNREE2TURBZ1FVME1UbTkwVTNCbFkybG1hV1Zrb2svdUZ6eFBQZFlBQUFBQUFBQkFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFFbXhwZG1VNmJtVm5iMk5wYjNOaGNIQnNaUUFBQUFBQUFBQUFBQWRPYjFOamIzSmxBQUFBQUFRQUFBQUFBQUFBQUFBQUFLSlA3aGM4VHozV0FBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQkVteHBkbVU2Ym1WbmIyTnBiM05oY0hCc1pRQUFBQUFBOVNVNFlBZ0FBQUFEVldsakNFbGtaVzUwYVhSNURrbGtaVzUwYVhSNVZYQmtZWFJsQ0VOdmJuUmhZM1J6RGtOdmJuUmhZM1J6VlhCa1lYUmxDRU52YlcxbGNtTmxEVU52YlcxMWJtbGpZWFJwYjI0VlEyOXRiWFZ1YVdOaGRHbHZibEpsWVdSUGJteDVBQUE9Ow==; expires=1614378869; endpointId={6bc6411e-41a7-4841-a85b-36c20d722a3e}
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36
X-ECS-Etag: "W08y7ExnU3KljSMB1R8XXkZOu3GBOVpI+vLNr6FS6Xk="


**ENDPOINT**
https://azeus1-client-s.gateway.messenger.live.com/v1/users/ME/conversations/4:+5531993818360/messages?x-ecs-etag="W08y7ExnU3KljSMB1R8XXkZOu3GBOVpI+vLNr6FS6Xk="    

**BODY**
clientmessageid: "7155319416505915828"
composetime: "2021-02-25T23:11:49.190Z"
content: "<sms alt="Hello test"><restApiVersion>2</restApiVersion><encoded_body>Hello test</encoded_body><defaults><skype><deliveryReportVersion>chatservice</deliveryReportVersion><uiVersion>1418/8.68.0.96</uiVersion></skype><control><flowId>skype.S4L.client.sms.1way</flowId><deliveryMethod>reliable</deliveryMethod></control><content><body>Hello test</body></content></defaults><bulkItems><bulkItem><requestId>c88a1865-8ab6-4f51-ba37-96b8e2807c70</requestId><recipient><address>+5531993818360</address></recipient></bulkItem></bulkItems></sms>"
contenttype: "text"
imdisplayname: "negociosapple apple"
messagetype: "RichText/Sms"
receiverdisplayname: "+5531993818360"

@Terrance
Copy link
Owner

You've leaked your tokens in there, best logout that session ASAP.


So there's a few things going on here that probably want handling:

  • phone contacts are type 4
  • SMSes have their own message type RichText/Sms along with a specific HTML structure

Does this work? (replacing +441234567890 with an actual contact's number)

chat = sk.chats["4:+441234567890"]
chat.sendRaw(
    messagetype="RichText/Sms",
    content="""<sms alt="Message text"><encoded_body>Message text</encoded_body></sms>""",
    imdisplayname="{0}".format(sk.user.name),
)

If not, does it work with the entire content line you quoted above?

@jeffersonveloso
Copy link

The test created the message just like in my tests here but the sms is not sent for some reason.

@Terrance
Copy link
Owner

Even with the full HTML message content?

@jeffersonveloso
Copy link

Even with the full HTML message content?

Yes, i try with the full HTML message content and not worked

@WaseemYoussef
Copy link

would be great if you can add reading/writing sms to this great project

@Terrance
Copy link
Owner

I don't have the Skype credit or a subscription to test this with, so this won't go anywhere unless someone can reliably reproduce a working Skype for Web request for sending an SMS using SkPy, like the one I proposed above.

It's a request to client-s.gateway.messenger.live.com and they're fairly standardised, so hopefully it doesn't depend on unusual parameters to work. SkypeChat.sendRaw() will do a POST request to the right URL (sending an SMS appears to use the same endpoint as a regular Skype message), with kwargs becoming the message body, so it should just be a case of finding the right combination of parameters.

@beepsoft
Copy link

I was able to send SMS using sendRaw and this template below once I already had a chat for a given phone number. In case the chat's ID is something like 4:+1123456789 and the phone number is +1123456789 this request worked for with a random UUID as the request_id:

<sms alt="{message}">
<restApiVersion>2</restApiVersion>
<encoded_body>{message}</encoded_body>
<defaults>
    <skype>
        <deliveryReportVersion>chatservice</deliveryReportVersion>
        <uiVersion>1418/8.133.0.202</uiVersion>
    </skype>
    <control>
        <flowId>skype.S4L.client.sms.1way</flowId>
        <deliveryMethod>reliable</deliveryMethod>
    </control>
    <content>
        <body>{message}</body>
    </content>
</defaults>
<bulkItems>
    <bulkItem>
        <requestId>{request_id}</requestId>
        <recipient>
            <address>{phone_number}</address>
        </recipient>
    </bulkItem>
</bulkItems>
</sms>

I actually have this in code:

                        # Extract phone number from chat ID (format: 4:+11123456789)
                        phone_number = chat_id.split(':')[1]
                        request_id = str(uuid.uuid4())
                        
                        # Construct SMS XML content
                        sms_content = f"""<sms alt="{message}">
<restApiVersion>2</restApiVersion>
<encoded_body>{message}</encoded_body>
<defaults>
    <skype>
        <deliveryReportVersion>chatservice</deliveryReportVersion>
        <uiVersion>1418/8.133.0.202</uiVersion>
    </skype>
    <control>
        <flowId>skype.S4L.client.sms.1way</flowId>
        <deliveryMethod>reliable</deliveryMethod>
    </control>
    <content>
        <body>{message}</body>
    </content>
</defaults>
<bulkItems>
    <bulkItem>
        <requestId>{request_id}</requestId>
        <recipient>
            <address>{phone_number}</address>
        </recipient>
    </bulkItem>
</bulkItems>
</sms>"""
                        
                        logging.info(f"Sending as SMS message to {phone_number}")
                        chat.sendRaw(
                            messagetype="RichText/Sms",
                            content=sms_content,
                            imdisplayname="{0}".format(sk.user.name),
                        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants