Multi-Channel Messaging with Cenit

Multichannels
Multi-Channel Messaging with Cenit
author By Maria Esther Guirola, Mar 1, 2016

In this post we are going to see how we can send messages to different channels through Cenit. We'll see how Cenit manage different authentication modes like basic authentication, OAuth 1.0 and OAuth 2.0.

We assume you have a Cenit account. If you do not have an account go on CenitSaaS and create one, it’s free.

Note: All examples use your Cenit account credentials (Key and Authentication token). Once inside Cenit you can find this, by clicking on your account name, under Credentials section.

Details Cenit account

Account credentials

Twilio Integration

1. First you need to pull Twilio collection. Go to Collections/SharedCollections, search twilio and pull it.

Shared collection

2. Twilio uses basic authentication, so the collection ask for Account SID and Auth Token . This parameters are required to let Cenit access to your account. So, you have to go to your Twilio account and select Account.

Pull Twilio collection

3. In Twilio go to Account and copy the generated Account SID and Auth Token. Put them in Cenit and click Pull button.

Twilio account

Twilio account credentials

4. Now you can create and send a message to Twilio using Cenit.io API. Twilio messages are available at: https://cenit.io/api/v1/twilio/message

To post a message to these URL just format a JSON document like this:

              {
                 "from": "(919) 617- 9297",
                 "to": "(704) 615-2238",
                 "body": "Hi!"
              }
            

The form phone should be a Twilio valid number. The destination phone should be a verified number phone in twilio, listed in: https://www.twilio.com/user/account/phone-numbers/verified

You can try it with the following curl command:

              curl -H "Content-Type: application/json"\
                   -H "X-User-Access-Key: XXXXXX"\
                   -H "X-User-Access-Token: YYYYYY"\
                   -X POST -d '{"from":"(919) 617- 9297","to":"(704) 615-2238","body":"Hi!"}'
                https://cenit.io/api/v1/twilio/message
              

Note: X-User-Access-Key and X-User-Access-Token are your Cenit account credentials.

Now, you can see the message in Twilio:

Message in Twilio

You can POST messages also in XML format:
<Message>
    <to> (919) 617- 9297 </to>
    <from> (704) 615-2238 </from>
    <body> Hi! </body>
</Message>

And that's all, you've sent a message through Cenit using your authorized Twilio account.



Twitter Integration

1. First you need to pull Twitter collection. Go to Collections/SharedCollections, search twitter and pull it.

Shared collection

2. Twitter uses OAuth 1.0 authentication, so, authorize your Twitter API OAuth1 authorization if it is not. For do this go to Security/Authorizations/OAuth 1.0.

Twitter authorization

3. Now you can create and send a message to Twitter using Cenit.io API. Twitter messages are available at: https://cenit.io/api/v1/twitter/tweet

To post a message to these URL just format a JSON document like this:

               {
                 "status": "Sent through Cenit.io API"
               }
            

You can try it with the following curl command:

              curl -H "Content-Type: application/json"\
                   -H "X-User-Access-Key: XXXXXX"\
                   -H "X-User-Access-Token: YYYYYY"\
                   -X POST -d '{ "status": "Sent through Cenit.io API"}'
                https://cenit.io/api/v1/twitter/tweet
            

Note: X-User-Access-Key and X-User-Access-Token are your Cenit account credentials.

Then, you can see the tweet:

Tweet

You can POST messages also in XML format:
<Tweet>
    <status>Sent through Cenit.io API</status>
</Tweet>

And that's all, you've sent a tweet through Cenit using your authorized Twitter account.



Gmail Integration

1. First you need to pull Gmail collection. Go to Collections/SharedCollections, search gmail and pull it.

Shared collection

2. Gmail uses OAuth 2.0 authentication, so, authorize your Gmail API OAuth 2.0 authorization, if it is not. For do this go to Security/Authorizations/OAuth 2.0.

Gmail authorization

3. Now, you can create a new MIME Message. MIME messages are available at https://cenit.io/api/v1/mime/message.

To post a message to these URL just format a JSON document like these:

              {
                "to": "someuser@gmail.com",
                "subject": "Hello",
                "body": "Just to say hello!"
              }
            

You can try it with the following curl command:

              curl -H "Content-Type: application/json"\
                   -H "X-User-Access-Key: XXXXXX"\
                   -H "X-User-Access-Token: YYYYYY"
                   -X POST -d '{"to":"someuser@gmail.com","subject":"Hello","body":"Just to say hello!"}'
               https://cenit.io/api/v1/mime/message
            

Note: X-User-Access-Key and X-User-Access-Token are your Cenit account credentials.

Now, you can see the sent message in the Gmail account:

Shared collection

That’s it! You've sent a message using your authorized Google account.

You can POST messages also in XML format:
<Message>
   <to> someuser@gmail.com </to>
   <subject> Hello </subject>
   <body> Just to say hello! </body>
</Message>

If you want to attach binary files you can encode them and specify the encoding format like these:

              {
                "to": "someuser@gmail.com",
                "subject": "See attachment",
                "attachments": [
                  {
                    "filename": "file.txt",
                    "encoding": "urlsafe_base64",
                    "data": "U2VudCB0aHJvdWdoIENlbml0SHViIEFQSQ=="
                  }]
              }
            

The availables encoding formats are:

  • base64
  • strict_base64
  • urlsafe_base64

For more information, please contact us by cenithub.com or send us a message to the email address support@cenit.io


Back to blog Get in touch